The default behavior is for system to pass this URI and append it with the query text. For example:
content://your.authority/optional.suggest.path/SUGGEST_URI_PATH_QUERY
/puppies
Instead of using the URI, you might decide it makes more sense for your
query()
method to receive everything it needs to perform the look-up and you want the
selection
and
selectionArgs
parameters to carry the appropriate values.
Declaring an Intent for Suggestions
When the user selects a suggestion from the list that appears below the search dialog or widget, the system sends a custom Intent
to your searchable activity. You must define the action and data for the intent.
android:searchSuggestIntentAction
attribute in your searchable configuration, then you
must
include a value in the
SUGGEST_COLUMN_INTENT_ACTION
column for every suggestion, or the intent will fail.
>You can define the data included with the intent in two ways:
- Define the data for each suggestion inside the
SUGGEST_COLUMN_INTENT_DATA
column of your suggestions table.
b.Fragment a data URI into two pieces: the portion common to all suggestions and the portion unique to each suggestion. Place these parts into the android:searchSuggestintentData
attribute of the searchable configuration and the SUGGEST_COLUMN_INTENT_DATA_ID
column of your suggestions table, respectively.
Declare the piece of the URI that is common to all suggestions in the android:searchSuggestIntentData
attribute of your searchable configuration.
<?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_label" android:hint="@string/search_hint" android:searchSuggestAuthority="com.example.MyCustomSuggestionProvider" android:searchSuggestIntentAction="android.intent.action.VIEW" android:searchSuggestIntentData="content://com.example/datatable"
> Here's an example of how you can handle the intents during your activityandroid:searchSettingsDescription="@string/search_description" ></searchable>
onCreate()
callback:
Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { // Handle the normal search query case String query = intent.getStringExtra(SearchManager.QUERY); doSearch(query); } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { // Handle a suggestions click (because the suggestions all use ACTION_VIEW) Uri data = intent.getData(); showResult(data); }
Note: You do not need to add an intent filter to your Android manifest file for the intent action you defined with the android:searchSuggestIntentAction
attribute or SUGGEST_COLUMN_INTENT_ACTION
column. The system opens your searchable activity by name to deliver the suggestion's intent, so the activity does not need to declare the accepted action.
> You can rewrite the query text in the following ways:
- Add the
android:searchMode
attribute to your searchable configuration with the "queryRewriteFromText" value. In this case, the content from the suggestion'sSUGGEST_COLUMN_TEXT_1
column is used to rewrite the query text. - Add the
android:searchMode
attribute to your searchable configuration with the "queryRewriteFromData" value. In this case, the content from the suggestion'sSUGGEST_COLUMN_INTENT_DATA
column is used to rewrite the query text. This should only be used with URI's or other data formats that are intended to be user-visible, such as HTTP URLs. Internal URI schemes should not be used to rewrite the query in this way. - Provide a unique query text string in the
SUGGEST_COLUMN_QUERY
column of your suggestions table. If this column is present and contains a value for the current suggestion, it is used to rewrite the query text (and override either of the previous implementations).
>The only scenario in which additional work is necessary is when your content provider demands a read permission. In which case, you need to add a special <path-permission>
element for the provider to grant Quick Search Box read access to your content provider. For example:
<provider android:name="MySuggestionProvider" android:authorities="com.example.MyCustomSuggestionProvider" android:readPermission="com.example.provider.READ_MY_DATA" android:writePermission="com.example.provider.WRITE_MY_DATA"> <path-permission android:pathPrefix="/search_suggest_query" android:readPermission="android.permission.GLOBAL_SEARCH" /> </provider>
>Suggestions that the user selects from Quick Search Box can be automatically made into shortcuts. These are suggestions that the system has copied from your content provider so it can quickly access the suggestion without the need to re-query your content provider.
>Using this column, you can configure the shortcut behavior for each suggestion in one of the following ways:
a.Have Quick Search Box re-query your content provider for a fresh version of the suggestion shortcut.
b.Prevent the suggestion from being copied into a shortcut at all.
c.Allow the default shortcut behavior to apply.
Note: Quick Search Box ultimately decides whether or not to create a shortcut for a suggestion, considering these values as a strong request from your application—there is no guarantee that the behavior you have requested for your suggestion shortcuts will be honored.
Note: Quick Search Box ultimately decides whether or not to create a shortcut for a suggestion, considering these values as a strong request from your application—there is no guarantee that the behavior you have requested for your suggestion shortcuts will be honored.
There is no guarantee about how your suggestions are ranked, or whether your app's suggestions show at all for a given query. In general, you can expect that providing quality results increases the likelihood that your app's suggestions are provided in a prominent position and apps that provide low quality suggestions are more likely to be ranked lower or not displayed.