public class SearchManager extends Object implements DialogInterface.OnDismissListener, DialogInterface.OnCancelListener
In practice, you won't interact with this class directly, as search
services are provided through methods in Activity
and the ACTION_SEARCH
Intent
.
If you do require direct access to the SearchManager, do not instantiate
this class directly. Instead, retrieve it through
context.getSystemService(Context.SEARCH_SERVICE)
.
For more information about using the search dialog and adding search suggestions in your application, read the Search developer guide.
Modifier and Type | Class and Description |
---|---|
static interface |
SearchManager.OnCancelListener
See
setOnCancelListener(android.app.SearchManager.OnCancelListener) for configuring your activity to monitor
search UI state. |
static interface |
SearchManager.OnDismissListener
See
setOnDismissListener(android.app.SearchManager.OnDismissListener) for configuring your activity to monitor
search UI state. |
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_KEY
Intent extra data key: Use this key with Intent.ACTION_SEARCH and
content.Intent.getIntExtra()
to obtain the keycode that the user used to trigger this query. |
static String |
ACTION_MSG
Intent extra data key: Use this key with Intent.ACTION_SEARCH and
content.Intent.getStringExtra()
to obtain the action message that was defined for a particular search action key and/or
suggestion. |
static String |
APP_DATA
Intent extra data key: Use this key with Intent.ACTION_SEARCH and
content.Intent.getBundleExtra()
to obtain any additional app-specific data that was inserted by the
activity that launched the search. |
static String |
CONTEXT_IS_VOICE
This means that context is voice, and therefore the SearchDialog should
continue showing the microphone until the user indicates that he/she does
not want to re-speak (e.g.
|
static String |
CURSOR_EXTRA_KEY_IN_PROGRESS
Boolean extra data key for a suggestion provider to return in
Cursor.getExtras() to
indicate that the search is not complete yet. |
static String |
DISABLE_VOICE_SEARCH
This means that the voice icon should not be shown at all, because the
current search engine does not support voice search.
|
static String |
EXTRA_DATA_KEY
Intent extra data key: This key will be used for the extra populated by the
SUGGEST_COLUMN_INTENT_EXTRA_DATA column. |
static String |
EXTRA_NEW_SEARCH
Boolean extra data key for
Intent.ACTION_WEB_SEARCH intents. |
static String |
EXTRA_SELECT_QUERY
Boolean extra data key for
INTENT_ACTION_GLOBAL_SEARCH intents. |
static String |
EXTRA_WEB_SEARCH_PENDINGINTENT
Extra data key for
Intent.ACTION_WEB_SEARCH . |
static int |
FLAG_QUERY_REFINEMENT
Flag to specify that the entry can be used for query refinement, i.e., the query text
in the search field can be replaced with the text in this entry, when a query refinement
icon is clicked.
|
static String |
INTENT_ACTION_GLOBAL_SEARCH
Intent action for starting the global search activity.
|
static String |
INTENT_ACTION_SEARCH_SETTINGS
Intent action for starting the global search settings activity.
|
static String |
INTENT_ACTION_SEARCH_SETTINGS_CHANGED
Intent action broadcasted to inform that the search settings have changed in some way.
|
static String |
INTENT_ACTION_SEARCHABLES_CHANGED
Intent action broadcasted to inform that the searchables list or default have changed.
|
static String |
INTENT_ACTION_WEB_SEARCH_SETTINGS
Intent action for starting a web search provider's settings activity.
|
static String |
INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED
Intent action to be broadcast to inform that the global search provider
has changed.
|
static char |
MENU_KEY
This is a shortcut definition for the default menu key to use for invoking search.
|
static int |
MENU_KEYCODE
This is a shortcut definition for the default menu key to use for invoking search.
|
static String |
QUERY
Intent extra data key: Use this key with
content.Intent.getStringExtra()
to obtain the query string from Intent.ACTION_SEARCH. |
static String |
SEARCH_MODE
Intent extra data key: Use
content.Intent.getBundleExtra(SEARCH_MODE) to get the search mode used
to launch the intent. |
static String |
SHORTCUT_MIME_TYPE
MIME type for shortcut validation.
|
static String |
SUGGEST_COLUMN_FLAGS
Column name for suggestions cursor.
|
static String |
SUGGEST_COLUMN_FORMAT
Column name for suggestions cursor.
|
static String |
SUGGEST_COLUMN_ICON_1
Column name for suggestions cursor.
|
static String |
SUGGEST_COLUMN_ICON_2
Column name for suggestions cursor.
|
static String |
SUGGEST_COLUMN_INTENT_ACTION
Column name for suggestions cursor.
|
static String |
SUGGEST_COLUMN_INTENT_DATA
Column name for suggestions cursor.
|
static String |
SUGGEST_COLUMN_INTENT_DATA_ID
Column name for suggestions cursor.
|
static String |
SUGGEST_COLUMN_INTENT_EXTRA_DATA
Column name for suggestions cursor.
|
static String |
SUGGEST_COLUMN_LAST_ACCESS_HINT
Column name for suggestions cursor.
|
static String |
SUGGEST_COLUMN_QUERY
Column name for suggestions cursor.
|
static String |
SUGGEST_COLUMN_SHORTCUT_ID
Column name for suggestions cursor.
|
static String |
SUGGEST_COLUMN_SPINNER_WHILE_REFRESHING
Column name for suggestions cursor.
|
static String |
SUGGEST_COLUMN_TEXT_1
Column name for suggestions cursor.
|
static String |
SUGGEST_COLUMN_TEXT_2
Column name for suggestions cursor.
|
static String |
SUGGEST_COLUMN_TEXT_2_URL
Column name for suggestions cursor.
|
static String |
SUGGEST_MIME_TYPE
MIME type for suggestions data.
|
static String |
SUGGEST_NEVER_MAKE_SHORTCUT
Column value for suggestion column
SUGGEST_COLUMN_SHORTCUT_ID when a suggestion
should not be stored as a shortcut in global search. |
static String |
SUGGEST_PARAMETER_LIMIT
Query parameter added to suggestion queries to limit the number of suggestions returned.
|
static String |
SUGGEST_URI_PATH_QUERY
Uri path for queried suggestions data.
|
static String |
SUGGEST_URI_PATH_SHORTCUT
Uri path for shortcut validation.
|
static String |
USER_QUERY
Intent extra data key: Use this key with
content.Intent.getStringExtra()
to obtain the query string typed in by the user. |
Modifier and Type | Method and Description |
---|---|
Intent |
getAssistIntent(Context context)
Gets an intent for launching installed assistant activity, or null if not available.
|
Intent |
getAssistIntent(Context context,
int userHandle)
Gets an intent for launching installed assistant activity, or null if not available.
|
List<ResolveInfo> |
getGlobalSearchActivities()
Returns a list of installed apps that handle the global search
intent.
|
ComponentName |
getGlobalSearchActivity()
Gets the name of the global search activity.
|
SearchableInfo |
getSearchableInfo(ComponentName componentName)
Gets information about a searchable activity.
|
List<SearchableInfo> |
getSearchablesInGlobalSearch()
Returns a list of the searchable activities that can be included in global search.
|
Cursor |
getSuggestions(SearchableInfo searchable,
String query)
Gets a cursor with search suggestions.
|
Cursor |
getSuggestions(SearchableInfo searchable,
String query,
int limit)
Gets a cursor with search suggestions.
|
ComponentName |
getWebSearchActivity()
Gets the name of the web search activity.
|
boolean |
isVisible()
Determine if the Search UI is currently displayed.
|
void |
onCancel(DialogInterface dialog)
Deprecated.
This method is an obsolete internal implementation detail. Do not use.
|
void |
onDismiss(DialogInterface dialog)
Deprecated.
This method is an obsolete internal implementation detail. Do not use.
|
void |
setOnCancelListener(SearchManager.OnCancelListener listener)
Set or clear the callback that will be invoked whenever the search UI is canceled.
|
void |
setOnDismissListener(SearchManager.OnDismissListener listener)
Set or clear the callback that will be invoked whenever the search UI is dismissed.
|
void |
startSearch(String initialQuery,
boolean selectInitialQuery,
ComponentName launchActivity,
Bundle appSearchData,
boolean globalSearch)
Launch search UI.
|
void |
startSearch(String initialQuery,
boolean selectInitialQuery,
ComponentName launchActivity,
Bundle appSearchData,
boolean globalSearch,
Rect sourceBounds)
As
startSearch(String, boolean, ComponentName, Bundle, boolean) but including
source bounds for the global search intent. |
void |
stopSearch()
Terminate search UI.
|
void |
triggerSearch(String query,
ComponentName launchActivity,
Bundle appSearchData)
Similar to
startSearch(java.lang.String, boolean, android.content.ComponentName, android.os.Bundle, boolean) but actually fires off the search query after invoking
the search dialog. |
public static final char MENU_KEY
public static final int MENU_KEYCODE
public static final String QUERY
content.Intent.getStringExtra()
to obtain the query string from Intent.ACTION_SEARCH.public static final String USER_QUERY
content.Intent.getStringExtra()
to obtain the query string typed in by the user.
This may be different from the value of QUERY
if the intent is the result of selecting a suggestion.
In that case, QUERY
will contain the value of
SUGGEST_COLUMN_QUERY
for the suggestion, and
USER_QUERY
will contain the string typed by the
user.public static final String APP_DATA
content.Intent.getBundleExtra()
to obtain any additional app-specific data that was inserted by the
activity that launched the search.public static final String SEARCH_MODE
content.Intent.getBundleExtra(SEARCH_MODE)
to get the search mode used
to launch the intent.
The only current value for this is #MODE_GLOBAL_SEARCH_SUGGESTION
.public static final String ACTION_KEY
content.Intent.getIntExtra()
to obtain the keycode that the user used to trigger this query. It will be zero if the
user simply pressed the "GO" button on the search UI. This is primarily used in conjunction
with the keycode attribute in the actionkey element of your searchable.xml configuration
file.public static final String EXTRA_DATA_KEY
SUGGEST_COLUMN_INTENT_EXTRA_DATA
column.public static final String EXTRA_SELECT_QUERY
INTENT_ACTION_GLOBAL_SEARCH
intents. If true
,
the initial query should be selected when the global search activity is started, so
that the user can easily replace it with another query.public static final String EXTRA_NEW_SEARCH
Intent.ACTION_WEB_SEARCH
intents. If true
,
this search should open a new browser window, rather than using an existing one.public static final String EXTRA_WEB_SEARCH_PENDINGINTENT
Intent.ACTION_WEB_SEARCH
. If set, the value must be a
PendingIntent
. The search activity handling the Intent.ACTION_WEB_SEARCH
intent will fill in and launch the pending intent. The data URI will be filled in with an
http or https URI, and Browser.EXTRA_HEADERS
may be filled in.public static final String CURSOR_EXTRA_KEY_IN_PROGRESS
Cursor.getExtras()
to
indicate that the search is not complete yet. This can be used by the search UI
to indicate that a search is in progress. The suggestion provider can return partial results
this way and send a change notification on the cursor when more results are available.public static final String ACTION_MSG
content.Intent.getStringExtra()
to obtain the action message that was defined for a particular search action key and/or
suggestion. It will be null if the search was launched by typing "enter", touched the the
"GO" button, or other means not involving any action key.public static final int FLAG_QUERY_REFINEMENT
Use this flag as a bit-field for SUGGEST_COLUMN_FLAGS
.
public static final String SUGGEST_URI_PATH_QUERY
public static final String SUGGEST_MIME_TYPE
public static final String SUGGEST_URI_PATH_SHORTCUT
public static final String SHORTCUT_MIME_TYPE
public static final String SUGGEST_COLUMN_FORMAT
public static final String SUGGEST_COLUMN_TEXT_1
public static final String SUGGEST_COLUMN_TEXT_2
public static final String SUGGEST_COLUMN_TEXT_2_URL
SUGGEST_COLUMN_TEXT_2
. This is a separate
column so that the search UI knows to display the text as a URL, e.g. by using a different
color. If this column is absent, or has the value null
,
SUGGEST_COLUMN_TEXT_2
will be used instead.public static final String SUGGEST_COLUMN_ICON_1
ContentResolver.SCHEME_CONTENT
)ContentResolver.SCHEME_ANDROID_RESOURCE
)ContentResolver.SCHEME_FILE
)ContentResolver.openAssetFileDescriptor(Uri, String)
for more information on these schemes.public static final String SUGGEST_COLUMN_ICON_2
ContentResolver.SCHEME_CONTENT
)ContentResolver.SCHEME_ANDROID_RESOURCE
)ContentResolver.SCHEME_FILE
)ContentResolver.openAssetFileDescriptor(Uri, String)
for more information on these schemes.public static final String SUGGEST_COLUMN_INTENT_ACTION
public static final String SUGGEST_COLUMN_INTENT_DATA
public static final String SUGGEST_COLUMN_INTENT_EXTRA_DATA
EXTRA_DATA_KEY
.public static final String SUGGEST_COLUMN_INTENT_DATA_ID
public static final String SUGGEST_COLUMN_QUERY
ACTION_SEARCH
, optional otherwise. If this
column exists and this element exists at the given row, this is the data that will be
used when forming the suggestion's query.public static final String SUGGEST_COLUMN_SHORTCUT_ID
SUGGEST_NEVER_MAKE_SHORTCUT
, the result will not be stored as a shortcut.
Otherwise, the shortcut id will be used to check back for an up to date suggestion using
SUGGEST_URI_PATH_SHORTCUT
.public static final String SUGGEST_COLUMN_SPINNER_WHILE_REFRESHING
public static final String SUGGEST_COLUMN_FLAGS
Must be one of FLAG_QUERY_REFINEMENT
or 0 to indicate no flags.
public static final String SUGGEST_COLUMN_LAST_ACCESS_HINT
System.currentTImeMillis()
(wall time in UTC) when an item was last
accessed within the results-providing application. If set, this may be
used to show more-recently-used items first.public static final String SUGGEST_NEVER_MAKE_SHORTCUT
SUGGEST_COLUMN_SHORTCUT_ID
when a suggestion
should not be stored as a shortcut in global search.public static final String SUGGEST_PARAMETER_LIMIT
public static final String INTENT_ACTION_GLOBAL_SEARCH
QUERY
,
EXTRA_SELECT_QUERY
,
APP_DATA
.public static final String INTENT_ACTION_SEARCH_SETTINGS
public static final String INTENT_ACTION_WEB_SEARCH_SETTINGS
public static final String INTENT_ACTION_SEARCHABLES_CHANGED
public static final String INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED
public static final String INTENT_ACTION_SEARCH_SETTINGS_CHANGED
public static final String CONTEXT_IS_VOICE
public static final String DISABLE_VOICE_SEARCH
public void startSearch(String initialQuery, boolean selectInitialQuery, ComponentName launchActivity, Bundle appSearchData, boolean globalSearch)
The search manager will open a search widget in an overlapping window, and the underlying activity may be obscured. The search entry state will remain in effect until one of the following events:
stopSearch()
method, which will hide the search window and return focus to the
activity from which it was launched.Most applications will not use this interface to invoke search.
The primary method for invoking search is to call
Activity.onSearchRequested()
or
Activity.startSearch()
.
initialQuery
- A search string can be pre-entered here, but this
is typically null or empty.selectInitialQuery
- If true, the intial query will be preselected, which means that
any further typing will replace it. This is useful for cases where an entire pre-formed
query is being inserted. If false, the selection point will be placed at the end of the
inserted query. This is useful when the inserted query is text that the user entered,
and the user would expect to be able to keep typing. This parameter is only meaningful
if initialQuery is a non-empty string.launchActivity
- The ComponentName of the activity that has launched this search.appSearchData
- An application can insert application-specific
context here, in order to improve quality or specificity of its own
searches. This data will be returned with SEARCH intent(s). Null if
no extra data is required.globalSearch
- If false, this will only launch the search that has been specifically
defined by the application (which is usually defined as a local search). If no default
search is defined in the current application or activity, global search will be launched.
If true, this will always launch a platform-global (e.g. web-based) search instead.Activity.onSearchRequested()
,
stopSearch()
public void startSearch(String initialQuery, boolean selectInitialQuery, ComponentName launchActivity, Bundle appSearchData, boolean globalSearch, Rect sourceBounds)
startSearch(String, boolean, ComponentName, Bundle, boolean)
but including
source bounds for the global search intent.public List<ResolveInfo> getGlobalSearchActivities()
public ComponentName getGlobalSearchActivity()
public ComponentName getWebSearchActivity()
null
if
there is no default web search activity.public void triggerSearch(String query, ComponentName launchActivity, Bundle appSearchData)
startSearch(java.lang.String, boolean, android.content.ComponentName, android.os.Bundle, boolean)
but actually fires off the search query after invoking
the search dialog. Made available for testing purposes.query
- The query to trigger. If empty, request will be ignored.launchActivity
- The ComponentName of the activity that has launched this search.appSearchData
- An application can insert application-specific
context here, in order to improve quality or specificity of its own
searches. This data will be returned with SEARCH intent(s). Null if
no extra data is required.startSearch(java.lang.String, boolean, android.content.ComponentName, android.os.Bundle, boolean)
public void stopSearch()
Typically the user will terminate the search UI by launching a search or by canceling. This function allows the underlying application or activity to cancel the search prematurely (for any reason).
This function can be safely called at any time (even if no search is active.)
public boolean isVisible()
public void setOnDismissListener(SearchManager.OnDismissListener listener)
listener
- The SearchManager.OnDismissListener
to use, or null.public void setOnCancelListener(SearchManager.OnCancelListener listener)
listener
- The SearchManager.OnCancelListener
to use, or null.@Deprecated public void onCancel(DialogInterface dialog)
DialogInterface.OnCancelListener
onCancel
in interface DialogInterface.OnCancelListener
dialog
- The dialog that was canceled will be passed into the
method.@Deprecated public void onDismiss(DialogInterface dialog)
DialogInterface.OnDismissListener
onDismiss
in interface DialogInterface.OnDismissListener
dialog
- The dialog that was dismissed will be passed into the
method.public SearchableInfo getSearchableInfo(ComponentName componentName)
componentName
- The activity to get searchable information for.null
if the activity does not
exist, or is not searchable.public Cursor getSuggestions(SearchableInfo searchable, String query)
searchable
- Information about how to get the suggestions.query
- The search text entered (so far).null the suggestion query failed.
public Cursor getSuggestions(SearchableInfo searchable, String query, int limit)
searchable
- Information about how to get the suggestions.query
- The search text entered (so far).limit
- The query limit to pass to the suggestion provider. This is advisory,
the returned cursor may contain more rows. Pass -1
for no limit.null the suggestion query failed.
public List<SearchableInfo> getSearchablesInGlobalSearch()
android:includeInGlobalSearch
attribute set
in their searchable meta-data.public Intent getAssistIntent(Context context)