In order to implement search with assistance from the Android system (to deliver search queries to an activity and provide search suggestions), your application must provide a search configuration in the form of an XML file.
This page describes the search configuration file in terms of its syntax and usage. For more information about how to implement search features for your application, begin with the developer guide about Creating a Search Interface.
<?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="string resource" android:hint="string resource" android:searchMode=["queryRewriteFromData" | "queryRewriteFromText"] android:searchButtonText="string resource" android:inputType="
imeOptions" android:searchSuggestAuthority="string" android:searchSuggestPath="string" android:searchSuggestSelection="string" android:searchSuggestIntentAction="string" android:searchSuggestIntentData="string" android:searchSuggestThreshold="int" android:includeInGlobalSearch=["true" | "false"] android:searchSettingsDescription="string resource" android:queryAfterZeroResults=["true" | "false"] android:voiceSearchMode=["showVoiceSearchButton" | "launchWebSearch" | "launchRecognizer"] android:voiceLanguageModel=["free-form" | "web_search"] android:voicePromptText="string resource" android:voiceLanguage="string" android:voiceMaxResults="int" > <actionkey android:keycode="
KEYCODE" android:queryActionMsg="string" android:suggestActionMsg="string" android:suggestActionMsgColumn="string" > </searchable>
android:labelattribute of your
<application>manifest element. This label is only visible to the user when you set
android:includeInGlobalSearchto "true", in which case, this label is used to identify your application as a searchable item in the system's search settings.
android:hintas "Search <content-or-product>". For example, "Search songs and artists" or "Search YouTube".
||Use the value from the
||Use the value from the
For more information, see the discussion about rewriting the query text in Adding Custom Suggestions.
inputTypefor a list of suitable values for this attribute.
imeOptionsfor a list of suitable values for this attribute.
If you have defined a content provider to generate search suggestions, you need to define additional attributes that configure communications with the content provider. When providing search suggestions, you need some of the following
android:authoritiesattribute of the Android manifest
Uri, after the prefix and authority, but before the standard suggestions path. This is only required if you have a single content provider issuing different types of suggestions (such as for different data types) and you need a way to disambiguate the suggestions queries when you receive them.
selectionparameter. Typically this is a WHERE clause for your database, and should contain a single question mark, which is a placeholder for the actual query string that has been typed by the user (for example,
"query=?"). However, you can also use any non-null value to trigger the delivery of the query text via the
selectionArgsparameter (and then ignore the
"android.intent.action.VIEW"). If this is not overridden by the selected suggestion (via the
SUGGEST_COLUMN_INTENT_ACTIONcolumn), this value is placed in the action field of the
Intentwhen the user clicks a suggestion.
SUGGEST_COLUMN_INTENT_DATAcolumn), this value is placed in the data field of the
Intentwhen the user clicks a suggestion.
To make your custom search suggestions available to Quick Search Box, you need some of the following
To enable voice search, you'll need some of the following
||Display a voice search button, if voice search is available on the device. If set, then either
||The voice search button takes the user directly to a built-in voice web search activity. Most applications don't need this flag, as it takes the user away from the activity in which search was invoked.|
||The voice search button takes the user directly to a built-in voice recording activity. This activity prompts the user to speak, transcribes the spoken text, and forwards the resulting query text to the searchable activity, just as if the user typed it into the search UI and clicked the search button.|
||Use free-form speech recognition for dictating queries. This is primarily optimized for English. This is the default.|
||Use web-search-term recognition for shorter, search-like phrases. This is available in more languages than "free_form".|
EXTRA_LANGUAGE_MODEL for more information.
"de"for German or
"fr"for French). This is needed only if it is different from the current value of
ACTION_SEARCHintent's primary query. Must be 1 or greater. Use
EXTRA_RESULTSto get the results from the intent. If not provided, the recognizer chooses how many results to return.
Not all action keys are available on every device, and not all keys are allowed to be overriden in this way. For example, the "Home" key cannot be used and must always return to the home screen. Also be sure not to define an action key for a key that's needed for typing a search query. This essentially limits the available and reasonable action keys to the call button and menu button. Also note that action keys are not generally discoverable, so you should not provide them as a core user feature.
You must define the
android:keycode to define the key and at least one of the other three attributes in order to define the search action.
KeyEventthat represents the action key you wish to respond to (for example
"KEYCODE_CALL"). This is added to the
ACTION_SEARCHintent that is passed to your searchable activity. To examine the key code, use
getIntExtra(SearchManager.ACTION_KEY). Not all keys are supported for a search action, as many of them are used for typing, navigation, or system functions.
ACTION_SEARCHintent that the system passes to your searchable activity. To examine the string, use
getStringExtra(SearchManager.ACTION_MSG). This should only be used if all your suggestions support this action key. If not all suggestions can handle the same action key, then you must instead use the following
android:suggestActionMsgattribute to define the action message for all suggestions, each entry in your content provider provides its own action message.
First, you must define a column in your content provider for each suggestion to provide an action message, then provide the name of that column in this attribute. The system looks at your suggestion cursor, using the string provided here to select your action message column, and then select the action message string from the Cursor. That string is added to the intent that the system passes to your searchable activity (using the action you've defined for suggestions). To examine the string, use
getStringExtra(SearchManager.ACTION_MSG). If the data does not exist for the selected suggestion, the action key is ignored.
<?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/search_label" android:hint="@string/search_hint" android:searchSuggestAuthority="dictionary" android:searchSuggestIntentAction="android.intent.action.VIEW" android:includeInGlobalSearch="true" android:searchSettingsDescription="@string/settings_description" > </searchable>