diff --git a/docs/html/guide/topics/search/adding-custom-suggestions.jd b/docs/html/guide/topics/search/adding-custom-suggestions.jd index 9ea4c8be48ea2..ce0c619536889 100644 --- a/docs/html/guide/topics/search/adding-custom-suggestions.jd +++ b/docs/html/guide/topics/search/adding-custom-suggestions.jd @@ -5,74 +5,88 @@ parent.link=index.html
The Android search framework provides the ability for your application to -provide suggestions while the user types into the Android search dialog. In this guide, you'll learn -how to create custom suggestions. These are suggestions based on custom data provided by your -application. For example, if your application is a word dictionary, you can suggest words from the -dictionary that match the text entered so far. These are the most valuable suggestions because you -can effectively predict what the user wants and provide instant access to it. Once you provide -custom suggestions, you then make them available to the system-wide Quick Search Box, providing -access to your content from outside your application.
+When using the Android search dialog, you can provide custom search suggestions that are +created from data in your application. For example, if your application is a word +dictionary, you can suggest words from the +dictionary that match the text entered so far. These are the most valuable suggestions, because you +can effectively predict what the user wants and provide instant access to it. Figure 1 shows +an example of a search dialog with custom suggestions.
-Before you begin, you need to have implemented the Android search dialog for searches in your
-application. If you haven't done this, see Using the Android Search
+ Once you provide custom suggestions, you can also make them available to the system-wide Quick
+Search Box, providing access to your content from outside your application. Before you begin with this guide to add custom suggestions, you need to have implemented the
+Android search dialog for searches in your
+application. If you haven't, see Using the Android Search
Dialog. Figure 1. Screenshot of a search dialog with custom
+search suggestions. When the user selects a custom suggestions, the Search Manager will send a customized Intent to
-your searchable Activity. Whereas a normal search query will send an Intent with the {@link
+ When the user selects a custom suggestion, the Search Manager sends an {@link
+android.content.Intent} to
+your searchable Activity. Whereas a normal search query sends an Intent with the {@link
android.content.Intent#ACTION_SEARCH} action, you can instead define your custom suggestions to use
-{@link android.content.Intent#ACTION_VIEW} (or any other action), and also include additional data
+{@link android.content.Intent#ACTION_VIEW} (or any other Intent action), and also include data
that's relevant to the selected suggestion. Continuing
the dictionary example, when the user selects a suggestion, your application can immediately
open the definition for that word, instead of searching the dictionary for matches. To provide custom suggestions, you need to do the following: To provide custom suggestions, do the following: Just like the Search Manager handles the rendering of the search dialog, it will also do the work
-to display all search suggestions below the search dialog. All you need to do is provide a source
-from which the suggestions can be retrieved. Note: If you're not familiar with creating Content
-Providers, please read the Content
+ Just like the Search Manager displays the search dialog, it also displays your search
+suggestions. All you need is a content provider from which the Search Manager can retrieve your
+suggestions. If you're not familiar with creating content
+providers, read the Content
Providers developer guide before you continue. When the Search Manager identifies that your Activity is searchable and also provides search
-suggestions, the following procedure will take place as soon as the user types into the Android
-search box: When the Search Manager identifies that your Activity is searchable and provides search
+suggestions, the following procedure takes place as soon as the user enters text into the
+search dialog: At this point, the following may happen: Once the custom suggestions are displayed, the following might happen: You may require some additional attributes, depending on the type of Intent you attach
+ You might need some additional attributes, depending on the type of Intent you attach
to each suggestion and how you want to format queries to your content provider. The other optional
-attributes are discussed in the relevant sections below.The Basics
-
+
+
-
-
+
+
-<?xml version="1.0" encoding="utf-8"?>
+<?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="my.package.MyCustomSuggestionProvider" >
-</searchable>
+ android:searchSuggestAuthority="com.example.MyCustomSuggestionProvider">
+</searchable>
-
Creating a content provider for custom suggestions requires previous knowledge about Content -Providers that's covered in the Creating a content provider for custom suggestions requires previous knowledge about content +providers that's covered in the Content Provider developer guide. For the most part, a content provider for custom suggestions is the same as any other content provider. However, for each suggestion you provide, the respective row in the {@link android.database.Cursor} must include specific columns that the Search Manager -understands.
+understands and uses to format the suggestions. -When the user starts typing into the search dialog, the Search Manager will query your Content -Provider for suggestions by calling {@link +
When the user starts typing into the search dialog, the Search Manager queries your content +provider for suggestions by calling {@link android.content.ContentProvider#query(Uri,String[],String,String[],String) query()} each time a letter is typed. In your implementation of {@link android.content.ContentProvider#query(Uri,String[],String,String[],String) query()}, your content provider must search your suggestion data and return a {@link -android.database.Cursor} that points to the rows you determine to be good suggestions.
+android.database.Cursor} that points to the rows you have determined to be good suggestions. -The following two sections describe how the Search Manager will send requests to your Content -Provider and how you can handle them, and define the columns that the Search Manager understands and -expects to be provided in the {@link android.database.Cursor} returned with each query.
+Details about creating a content provider for custom suggestions are discussed in the following +two sections:
+When the Search Manager makes a request for suggestions from your content provider, it will call -{@link android.content.ContentProvider#query(Uri,String[],String,String[],String)}. You must -implement this method in your content provider so that it will search your suggestions and return a -Cursor that contains the suggestions you deem relevant.
+When the Search Manager requests suggestions from your content provider, it calls your content +provider's {@link android.content.ContentProvider#query(Uri,String[],String,String[],String) +query()} method. You must +implement this method to search your suggestion data and return a +{@link android.database.Cursor} pointing to the suggestions you deem relevant.
-Here's a summary of the parameters that the Search Manager will pass to your {@link +
Here's a summary of the parameters that the Search Manager passes to your {@link android.content.ContentProvider#query(Uri,String[],String,String[],String) query()} method (listed in order):
uri
content://your.authority/optional.suggest.path/{@link
android.app.SearchManager#SUGGEST_URI_PATH_QUERY}
@@ -184,46 +202,48 @@ For example:
content://your.authority/optional.suggest.path/{@link
android.app.SearchManager#SUGGEST_URI_PATH_QUERY}/puppies
-The query text on the end will be encoded using URI encoding rules, so you may need to decode -it.
+The query text on the end is encoded using URI encoding rules, so you might need to decode +it before performing a search.
The {@code optional.suggest.path} portion is only included in the URI if you have set such a path in your searchable configuration file with the {@code android:searchSuggestPath} attribute. This is only needed if you use the same content provider for multiple searchable -activities, in which case you need to disambiguate the source of the suggestion query.
-Note that {@link android.app.SearchManager#SUGGEST_URI_PATH_QUERY} is not the literal +activities, in which case, you need to disambiguate the source of the suggestion query.
+Note: {@link +android.app.SearchManager#SUGGEST_URI_PATH_QUERY} is not the literal string provided in the URI, but a constant that you should use if you need to refer to this path.
projectionselectionselectionArgssortOrderAs you may have realized, there are two ways by which the Search Manager can send you the search -query text. The default manner is for the query text to be included as the last path of the content -URI that is passed in the {@code uri} parameter. However, if you include a selection value in your +
The Search Manager can send you the search query text in two ways. The +default manner is for the query text to be included as the last path of the content +URI passed in the {@code uri} parameter. However, if you include a selection value in your searchable configuration's {@code -android:searchSuggestSelection} attribute, then the query text will instead be passed as the first -element of the {@code selectionArgs} string array. Both options are summarized below.
+android:searchSuggestSelection} attribute, then the query text is instead passed as the first +element of the {@code selectionArgs} string array. Both options are summarized next. -By default, the query will be appended as the last segment of the {@code uri} +
By default, the query is appended as the last segment of the {@code uri} parameter (a {@link android.net.Uri} object). To retrieve the query text in this case, simply use {@link android.net.Uri#getLastPathSegment()}. For example:
@@ -231,52 +251,59 @@ parameter (a {@link android.net.Uri} object). To retrieve the query text in this String query = uri.getLastPathSegment().toLowerCase(); -This will return the last segment of the Uri, which is the query text entered in the search -dialog.
+This returns the last segment of the {@link android.net.Uri}, which is the query text entered in +the search dialog.
-Instead of using the URI, you may decide it makes more sense for your {@link +
Instead of using the URI, you might decide it makes more sense for your {@link android.content.ContentProvider#query(Uri,String[],String,String[],String) query()} method to receive everything it needs to perform the look-up and you want the -{@code selection} and {@code selectionArgs} parameters to carry values. In this case, you can -add the {@code android:searchSuggestSelection} attribute to your searchable configuration with your -SQLite selection string. In this selection string, you can include a question mark ("?") as -a placeholder for the actual search query. This selection string will be delivered as the -{@code selection} string parameter, and the query entered into the search dialog will be delivered -as the first element in the {@code selectionArgs} string array parameter.
+{@code selection} and {@code selectionArgs} parameters to carry the appropriate values. In such a +case, add the {@code android:searchSuggestSelection} attribute to your searchable configuration with +your SQLite selection string. In the selection string, include a question mark ("?") as +a placeholder for the actual search query. The Search Manager calls {@link +android.content.ContentProvider#query(Uri,String[],String,String[],String) query()} with the +selection string as the {@code selection} parameter and the search query as the first +element in the {@code selectionArgs} array.For example, here's how you might form the {@code android:searchSuggestSelection} attribute to create a full-text search statement:
-<?xml version="1.0" encoding="utf-8"?>
+<?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="my.package.MyCustomSuggestionProvider"
+ android:searchSuggestAuthority="com.example.MyCustomSuggestionProvider"
android:searchSuggestIntentAction="android.Intent.action.VIEW"
- android:searchSuggestSelection="word MATCH ?">
-</searchable>
+ android:searchSuggestSelection="word MATCH ?">
+</searchable>
-When you then receive the {@code selection} and {@code selectionArgs} parameters in your {@link -android.content.ContentProvider#query(Uri,String[],String,String[],String) ContentProvider.query()} -method, they will carry the selection ("word MATCH ?") and the query text, respectively. When -these are passed to an SQLite {@link -android.database.sqlite.SQLiteDatabase#query(String,String[],String,String[],String,String, -String) query} method, they will be synthesized together (replacing the question mark with the query -text, wrapped in single-quotes). Note that if you chose this method and need to add any wildcards to -your query text, you must do so by appending (and/or prefixing) them to the {@code selectionArgs} -parameter, because this is the value that will be wrapped in quotes and inserted in place of the +
With this configuration, your {@link +android.content.ContentProvider#query(Uri,String[],String,String[],String) query()} method +delivers the {@code selection} parameter as "word MATCH ?" and the {@code selectionArgs} +parameter as whatever the user entered in the search dialog. When you pass these to an SQLite +{@link android.database.sqlite.SQLiteDatabase#query(String,String[],String,String[],String,String, +String) query()} method, as their respective arguments, they are synthesized together (the +question mark is replaced with the query +text). If you chose to receive suggestion queries this way and need to add wildcards to +the query text, append (and/or prefix) them to the {@code selectionArgs} +parameter, because this value is wrapped in quotes and inserted in place of the question mark.
+Another new attribute in the example above is {@code android:searchSuggestIntentAction}, which +defines the Intent action sent with each Intent when the user selects a suggestion. It is +discussed further in the section about Declaring an Intent for +suggestions.
+Tip: If you don't want to define a selection clause in the {@code android:searchSuggestSelection} attribute, but would still like to receive the query text in the {@code selectionArgs} parameter, simply provide a non-null value for the {@code -android:searchSuggestSelection} attribute. This will trigger the query to be passed in {@code +android:searchSuggestSelection} attribute. This triggers the query to be passed in {@code selectionArgs} and you can ignore the {@code selection} parameter. In this way, you can instead define the actual selection clause at a lower level so that your content provider doesn't have to handle it.
@@ -287,11 +314,12 @@ handle it.If your search suggestions are not stored in a table format using the columns required by the +
If your search suggestions are not stored in a table format (such as an SQLite table) using the +columns required by the Search Manager, then you can search your suggestion data for matches and then format them -into the necessary table on the fly. To do so, create a {@link android.database.MatrixCursor} using -the required column names and then add a row for each suggestion using {@link +into the necessary table on each request. To do so, create a {@link android.database.MatrixCursor} +using the required column names and then add a row for each suggestion using {@link android.database.MatrixCursor#addRow(Object[])}. Return the final product from your Content Provider's {@link android.content.ContentProvider#query(Uri,String[],String,String[],String) query()} method.
@@ -299,97 +327,94 @@ android.content.ContentProvider#query(Uri,String[],String,String[],String) queryWhen you return suggestions to the Search Manager with a {@link android.database.Cursor}, the -Search Manager expects there to be specific columns in each row. So, regardless of whether you +Search Manager expects specific columns in each row. So, regardless of whether you decide to store your suggestion data in an SQLite database on the device, a database on a web server, or another format on the device or web, you must format the suggestions as rows in a table and -present them with a {@link android.database.Cursor}. There are several columns that the Search -Manager will understand, but only two are required:
+present them with a {@link android.database.Cursor}. The Search +Manager understands several columns, but only two are required:The following columns are all optional (and most will be discussed further in the following -sections, so you may want to skip this list for now):
+The following columns are all optional (and most are discussed further in the following +sections):
Again, most of these columns will be discussed in the relevant sections below, so don't worry if -they don't make sense to you now.
+Some of these columns are discussed more in the following sections.
When the user selects a suggestion from the list that appears below the search -dialog (instead of performing a search), the Search Manager will send -a custom {@link android.content.Intent} to your searchable Activity. You must define both the -action and data for the Intent.
+When the user selects a suggestion from the list that appears below the search dialog, the Search +Manager sends a custom {@link android.content.Intent} to your searchable Activity. You must define +the action and data for the Intent.
The most common Intent action for a custom suggestion is {@link android.content.Intent#ACTION_VIEW}, which is appropriate when you want to open something, like the definition for a word, a person's contact information, or a web -page. However, the Intent action can be whatever you want and can even be different for each +page. However, the Intent action can be any other action and can even be different for each suggestion.
-To declare an Intent action that will be the same for all suggestions, define the action in -the {@code android:searchSuggestIntentAction} attribute of your searchable configuration file. For -example:
+Depending on whether you want all suggestions to use the same Intent action, you +can define the action in two ways:
+ +For example:
<?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="my.package.MySuggestionProvider"
- android:searchSuggestIntentAction="android.Intent.action.VIEW" >
+ android:searchSuggestAuthority="com.example.MyCustomSuggestionProvider"
+ android:searchSuggestIntentAction="android.Intent.action.VIEW" >
</searchable>
-If you want to declare an Intent action that's unique for each suggestion, add the {@link -android.app.SearchManager#SUGGEST_COLUMN_INTENT_ACTION} column to +
Add the {@link android.app.SearchManager#SUGGEST_COLUMN_INTENT_ACTION} column to your suggestions table and, for each suggestion, place in it the action to use (such as -{@code "android.Intent.action.VIEW"}).
+{@code "android.Intent.action.VIEW"}). + +You can also combine these two techniques. For instance, you can include the {@code android:searchSuggestIntentAction} attribute with an action to be used with all suggestions by default, then override this action for some suggestions by declaring a different action in the {@link android.app.SearchManager#SUGGEST_COLUMN_INTENT_ACTION} column. If you do not include a value in the {@link android.app.SearchManager#SUGGEST_COLUMN_INTENT_ACTION} column, then the -Intent provided in the {@code android:searchSuggestIntentAction} attribute will be used.
+Intent provided in the {@code android:searchSuggestIntentAction} attribute is used.Note: If you do not include the {@code android:searchSuggestIntentAction} attribute in your searchable configuration, then you @@ -432,45 +465,45 @@ Intent provided in the {@code android:searchSuggestIntentAction} attribute will column for every suggestion, or the Intent will fail.
+When the user selects a suggestion, your searchable Activity will receive the Intent with the +
When the user selects a suggestion, your searchable Activity receives the Intent with the action you've defined (as discussed in the previous section), but the Intent must also carry -data in order for your Activity to identify which suggestions was selected. Specifically, +data in order for your Activity to identify which suggestion was selected. Specifically, the data should be something unique for each suggestion, such as the row ID for the suggestion in -your suggestions table. When the Intent is received, +your SQLite table. When the Intent is received, you can retrieve the attached data with {@link android.content.Intent#getData()} or {@link android.content.Intent#getDataString()}.
-There are two ways to define the data that is included with the Intent:
+You can define the data included with the Intent in two ways:
Provide all necessary data information for each Intent in the suggestions table by including the +{@link android.app.SearchManager#SUGGEST_COLUMN_INTENT_DATA} column and then populating it with +unique data for each row. The data from this column is attached to the Intent exactly as you +define it in this column. You can then retrieve it with with {@link +android.content.Intent#getData()} or {@link android.content.Intent#getDataString()}.
+ +Tip: It's usually easiest to use the table's row ID as the +Intent data, because it's always unique. And the easiest way to do that is by using the +{@link android.app.SearchManager#SUGGEST_COLUMN_INTENT_DATA} column name as an alias for the row ID +column. See the Searchable Dictionary sample +app for an example in which {@link android.database.sqlite.SQLiteQueryBuilder} creates a +projection map of column names to aliases.
+ +The first option is straight-forward. Simply provide all necessary data information for each -Intent in the suggestions table by including the {@link -android.app.SearchManager#SUGGEST_COLUMN_INTENT_DATA} column and then populating it with unique -data for each row. The data from this column will be attached to the Intent exactly as it -is found in this column. You can then retrieve it with with {@link android.content.Intent#getData()} -or {@link android.content.Intent#getDataString()}.
- -Tip: It's usually easiest to use the table's row ID as the -Intent data because it's always unique. And the easiest way to do that is by using the -{@link android.app.SearchManager#SUGGEST_COLUMN_INTENT_DATA} column name as an alias for the row ID -column. See the Searchable Dictionary sample -app for an example in which {@link android.database.sqlite.SQLiteQueryBuilder} is used to -create a projection map of column names to aliases.
- -The second option is to fragment your data URI into the common piece and the unique piece. -Declare the piece of the URI that is common to all suggestions in the {@code +
Declare the piece of the URI that is common to all suggestions in the {@code android:searchSuggestIntentData} attribute of your searchable configuration. For example:
@@ -478,35 +511,40 @@ android:searchSuggestIntentData} attribute of your searchable configuration. For
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_label"
android:hint="@string/search_hint"
- android:searchSuggestAuthority="my.package.MySuggestionProvider"
+ android:searchSuggestAuthority="com.example.MyCustomSuggestionProvider"
android:searchSuggestIntentAction="android.Intent.action.VIEW"
- android:searchSuggestIntentData="content://my.package/datatable" >
+ android:searchSuggestIntentData="content://com.example/datatable" >
</searchable>
-Now include the final path for each suggestion (the unique part) in the {@link +
Then include the final path for each suggestion (the unique part) in the {@link android.app.SearchManager#SUGGEST_COLUMN_INTENT_DATA_ID} -column of your suggestions table. When the user selects a suggestion, the Search Manager will take -the string from {@code android:searchSuggestIntentData}, append a slash ("/") and then add the +column of your suggestions table. When the user selects a suggestion, the Search Manager takes +the string from {@code android:searchSuggestIntentData}, appends a slash ("/") and then adds the respective value from the {@link android.app.SearchManager#SUGGEST_COLUMN_INTENT_DATA_ID} column to form a complete content URI. You can then retrieve the {@link android.net.Uri} with with {@link android.content.Intent#getData()}.
+ + +If you need to express even more information with your Intent, you can add another table column, {@link android.app.SearchManager#SUGGEST_COLUMN_INTENT_EXTRA_DATA}, which can store additional -information about the suggestion. The data saved in this column will be placed in {@link +information about the suggestion. The data saved in this column is placed in {@link android.app.SearchManager#EXTRA_DATA_KEY} of the Intent's extra Bundle.
+Now that your search dialog provides custom search suggestions with custom formatted Intents, you -need your searchable Activity to handle these Intents as they are delivered once the user selects a -suggestion. (This is, of course, in addition to handling the {@link -android.content.Intent#ACTION_SEARCH} Intent, which your searchable Activity already does.) -Accepting the new Intent is rather self-explanatory, so we'll skip straight to an example:
+Now that your search dialog provides custom search suggestions with custom Intents, you +need your searchable Activity to handle these Intents when the user selects a +suggestion. This is in addition to handling the {@link +android.content.Intent#ACTION_SEARCH} Intent, which your searchable Activity already does. +Here's an example of how you can handle the Intents during your Activity {@link +android.app.Activity#onCreate(Bundle) onCreate()} callback:
Intent intent = getIntent();
@@ -515,26 +553,32 @@ if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doSearch(query);
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
- // Handle a suggestions click (because my suggestions all use ACTION_VIEW)
- Uri data = intent.getData());
- showResult(rowId);
+ // Handle a suggestions click (because the suggestions all use ACTION_VIEW)
+ Uri data = intent.getData();
+ showResult(data);
}
In this example, the Intent action is {@link android.content.Intent#ACTION_VIEW} and the data carries a complete URI pointing to the suggested item, as synthesized by the {@code android:searchSuggestIntentData} string and {@link -android.app.SearchManager#SUGGEST_COLUMN_INTENT_DATA_ID} column. The URI is then passed to a local -method that will query the content provider for the item specified by the URI and show it.
+android.app.SearchManager#SUGGEST_COLUMN_INTENT_DATA_ID} column. The URI is then passed to the local +{@code showResult()} method that queries the content provider for the item specified by the URI. +Note: You do not need to add an Intent filter to your +Android manifest file for the Intent action you defined with the {@code +android:searchSuggestIntentAction} attribute or {@link +android.app.SearchManager#SUGGEST_COLUMN_INTENT_ACTION} column. The Search Manager opens your +searchable Activity by name to deliver the suggestion's Intent, so the Activity does not need to +declare the accepted action.
If the user navigates through the suggestions list using the device directional controls, the -text in the search dialog won't change, by default. However, you can temporarily rewrite the -user's query text as it appears in the text box with -a query that matches the currently selected suggestion. This enables the user to see what query is +
If the user navigates through the suggestions list using the directional controls (trackball or +d-pad), the text in the search dialog won't change, by default. However, you can temporarily rewrite +the user's query text as it appears in the text box with +a query that matches the suggestion currently in focus. This enables the user to see what query is being suggested (if appropriate) and then select the search box and edit the query before dispatching it as a search.
@@ -544,39 +588,40 @@ dispatching it as a search.Once your application is configured to provide custom search suggestions, making them available -to the globally-accessible Quick Search Box is as easy as modifying your searchable configuration to +
Once you configure your application to provide custom search suggestions, making them available +to the globally accessible Quick Search Box is as easy as modifying your searchable configuration to include {@code android:includeInGlobalSearch} as "true".
-The only scenario in which additional work will be required is if your content provider for -custom suggestions requires a permission for read access. In which case, you need to add a special -{@code <path-permission>} element for the provider to grant Quick Search Box read access to your -content provider. For example:
+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 +{@code <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="my.package.authority"
+ android:authorities="com.example.MyCustomSuggestionProvider"
android:readPermission="com.example.provider.READ_MY_DATA"
- android:writePermission="com.example.provider.WRITE_MY_DATA">
+ android:writePermission="com.example.provider.WRITE_MY_DATA">
<path-permission android:pathPrefix="/search_suggest_query"
- android:readPermission="android.permission.GLOBAL_SEARCH" />
-</provider>
+ android:readPermission="android.permission.GLOBAL_SEARCH" />
+</provider>
In this example, the provider restricts read and write access to the content. The @@ -585,8 +630,8 @@ inside the {@code "/search_suggest_query"} path prefix when the {@code "android.permission.GLOBAL_SEARCH"} permission exists. This grants access to Quick Search Box so that it may query your content provider for suggestions.
-Content providers that enforce no permissions are already available to the search -infrastructure.
+If your content provider does not enforce read permissions, then Quick Search Box can read +it by default.
The string for {@code android:searchSettingsDescription} should be as concise as possible and state the content that is searchable. For example, "Artists, albums, and tracks" for a music application, or "Saved notes" for a notepad application. Providing this description is important so -the user knows what kind of suggestions will be provided. This attribute should always be included +the user knows what kind of suggestions are provided. You should always include this attribute when {@code android:includeInGlobalSearch} is "true".
-Remember that the user must visit this settings menu to enable search suggestions for your -application before your search suggestions will appear in Quick Search Box. As such, if search is an -important aspect of your application, then you may want to consider a way to message this to your -users — perhaps with a note the first time they launch the app about how to enable search -suggestions for Quick Search Box.
+Remember that the user must visit the settings menu to enable search suggestions for your +application before your search suggestions appear in Quick Search Box. As such, if search is an +important aspect of your application, then you might want to consider a way to convey that to +your users — you might provide a note the first time they launch the app that instructs +them how to enable search suggestions for Quick Search Box.
Suggestions that the user selects from Quick Search Box may be automatically made into shortcuts. +
Suggestions that the user selects from Quick Search Box can be automatically made into shortcuts. These are suggestions that the Search Manager has copied from your content provider so it can quickly access the suggestion without the need to re-query your content provider.
By default, this is enabled for all suggestions retrieved by Quick Search Box, but if your -suggestion data may change over time, then you can request that the shortcuts be refreshed. For +suggestion data changes over time, then you can request that the shortcuts be refreshed. For instance, if your suggestions refer to dynamic data, such as a contact's presence status, then you should request that the suggestion shortcuts be refreshed when shown to the user. To do so, include the {@link android.app.SearchManager#SUGGEST_COLUMN_SHORTCUT_ID} in your suggestions table. Using this column, you can -configure the shortcut behavior for each suggestion in the following ways:
+configure the shortcut behavior for each suggestion in one of the following ways:Provide a value in the {@link android.app.SearchManager#SUGGEST_COLUMN_SHORTCUT_ID} column -and the suggestion will be -re-queried for a fresh version of the suggestion each time the shortcut is displayed. The shortcut -will be quickly displayed with whatever data was most recently available until the refresh query -returns, after which the suggestion will be dynamically refreshed with the new information. The -refresh query will be sent to your content provider with a URI path of {@link +and the suggestion is +re-queried for a fresh version each time the shortcut is displayed. The shortcut +is quickly displayed with whatever data was most recently available until the refresh query +returns, at which point the suggestion is refreshed with the new information. The +refresh query is sent to your content provider with a URI path of {@link android.app.SearchManager#SUGGEST_URI_PATH_SHORTCUT} -(instead of {@link android.app.SearchManager#SUGGEST_URI_PATH_QUERY}). The Cursor you return should -contain one suggestion using the +(instead of {@link android.app.SearchManager#SUGGEST_URI_PATH_QUERY}).
+The {@link android.database.Cursor} you return should contain one suggestion using the same columns as the original suggestion, or be empty, indicating that the shortcut is no -longer valid (in which case, the suggestion will disappear and the shortcut will be removed).
-If a suggestion refers to data that could take longer to refresh, such as a network based -refresh, you may also add the {@link +longer valid (in which case, the suggestion disappears and the shortcut is removed).
+If a suggestion refers to data that could take longer to refresh, such as a network-based +refresh, you can also add the {@link android.app.SearchManager#SUGGEST_COLUMN_SPINNER_WHILE_REFRESHING} column to your suggestions table with a value of "true" in order to show a progress spinner for the right hand icon until the refresh is complete. -(Any value other than "true" will not show the progress spinner.)
Provide a value of {@link android.app.SearchManager#SUGGEST_NEVER_MAKE_SHORTCUT} in the {@link android.app.SearchManager#SUGGEST_COLUMN_SHORTCUT_ID} column. In -this case, the suggestion will never be copied into a shortcut. This should only be necessary if you -absolutely do not want the previously copied suggestion to appear at all. (Recall that if you -provide a normal value for the column then the suggestion shortcut will appear only until the +this case, the suggestion is never copied into a shortcut. This should only be necessary if you +absolutely do not want the previously copied suggestion to appear. (Recall that if you +provide a normal value for the column, then the suggestion shortcut appears only until the refresh query returns.)
Simply leave the {@link android.app.SearchManager#SUGGEST_COLUMN_SHORTCUT_ID} empty for each +
Leave the {@link android.app.SearchManager#SUGGEST_COLUMN_SHORTCUT_ID} empty for each suggestion that will not change and can be saved as a shortcut.
Of course, if none of your suggestions will ever change, then you do not need the +
If none of your suggestions ever change, then you do not need the {@link android.app.SearchManager#SUGGEST_COLUMN_SHORTCUT_ID} column at all.
-Note: Quick Search Box will ultimately decide whether to shortcut -your app's suggestions, considering these values as a strong request from your application.
+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.
Once your application's search results are made available to Quick Search Box, how they surface -to the user for a particular query will be determined as appropriate by Quick Search Box ranking. -This may depend on how many other apps have results for that query, and how often the user has -selected on your results compared to those of the other apps. There is no guarantee about how -ranking will occur, or whether your app's suggestions will show at all for a given query. In -general, you can expect that providing quality results will increase the likelihood that your app's -suggestions are provided in a prominent position, and apps that provide lower quality suggestions -will be more likely to be ranked lower and/or not displayed.
+Once you make your application's search suggestions available to Quick Search Box, the Quick +Search Box ranking determines how the suggestions are surfaced to the user for a particular query. +This might depend on how many other apps have results for that query, and how often the user has +selected your results compared to those from other apps. 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.
See the Searchable
diff --git a/docs/html/guide/topics/search/adding-recent-query-suggestions.jd b/docs/html/guide/topics/search/adding-recent-query-suggestions.jd
index 37e0e8275edff..cb063a13fcac9 100644
--- a/docs/html/guide/topics/search/adding-recent-query-suggestions.jd
+++ b/docs/html/guide/topics/search/adding-recent-query-suggestions.jd
@@ -5,20 +5,22 @@ parent.link=index.html
The Android search framework provides the ability for your application to
-provide suggestions while the user types into the Android search dialog. In this guide, you'll learn
-how to create recent query suggestions. These are suggestions based
-on queries previously entered by the user. So, if the user previously searched for "puppies" then it
-will appear as a suggestion as they begin typing the same string of text. The screenshot below
-shows an example of recent query suggestions. When using the Android search dialog, you can provide search suggestions based on recent search
+queries. For example, if a user previously searched for "puppies," then that query appears as a
+suggestion once he or she begins typing the same query. Figure 1 shows an example of a search dialog
+with recent query suggestions. Before you begin, you need to implement the search dialog for basic searches in your application.
+If you haven't, see Using the Android Search Dialog. Before you begin, you need to have implemented the Android search dialog for searches in your
-application. If you haven't done this, see Using the Android Search
-Dialog. Figure 1. Screenshot of a search dialog with recent query
+suggestions. Recent query suggestions are simply saved searches. When the user selects one of
-the suggestions, your searchable Activity will receive a normal {@link
+the suggestions, your searchable Activity receives a {@link
android.content.Intent#ACTION_SEARCH} Intent with the suggestion as the search query, which your
-searchable Activity will already handle.In this document
+
+
+
Key classes
-In this document
-
-
+
See also
The Basics
-
+
+
To provide recent queries suggestions, you need to:
Just like the Search Manager handles the rendering of the search dialog, it will also do the work -to display all search suggestions below the search dialog. All you need to do is provide a source -from which the suggestions can be retrieved.
+Just as the Search Manager displays the search dialog, it also displays the +search suggestions. All you need to do is provide a source from which the suggestions can be +retrieved.
-When the Search Manager identifies that your Activity is searchable and also provides search -suggestions, the following procedure will take place as soon as the user types into the Android -search box:
+When the Search Manager identifies that your Activity is searchable and provides search +suggestions, the following procedure takes place as soon as the user types into the search +dialog:
+ +Once the recent query suggestions are displayed, the following might happen:
At this point, the following may happen:
- -As you'll soon discover, the {@link android.content.SearchRecentSuggestionsProvider} class that -you'll extend for your content provider will automatically do the work described above, so there's +
The {@link android.content.SearchRecentSuggestionsProvider} class that +you extend for your content provider automatically does the work described above, so there's actually very little code to write.
-First, you need to add the {@code android:searchSuggestAuthority} and -{@code android:searchSuggestSelection} attributes to the {@code <searchable>} element in your -searchable configuration file. For example:
- --<?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="my.package.MySuggestionProvider" - android:searchSuggestSelection=" ?" > -</searchable> -- -
The value for {@code android:searchSuggestAuthority} should be a fully-qualified name for -your content provider: your application package name followed by the name of your content provider. -This string must match the authority used in the content provider (discussed in the next section). -
- -The value for {@code android:searchSuggestSelection} must be a single question-mark, preceded by -a space (" ?"), which is simply a placeholder for the SQLite selection argument (which will be -automatically replaced by the query text entered by the user).
-
public class MySuggestionProvider extends SearchRecentSuggestionsProvider {
- public final static String AUTHORITY = "my.package.MySuggestionProvider";
+ public final static String AUTHORITY = "com.example.MySuggestionProvider";
public final static int MODE = DATABASE_MODE_QUERIES;
public MySuggestionProvider() {
@@ -140,41 +119,72 @@ public class MySuggestionProvider extends SearchRecentSuggestionsProvider {
}
-The call to {@link android.content.SearchRecentSuggestionsProvider#setupSuggestions(String,int)} -passes the name of the search authority (matching the one in the searchable configuration) and a -database mode. The database mode must include {@link +
The call to {@link android.content.SearchRecentSuggestionsProvider#setupSuggestions(String,int) +setupSuggestions()} passes the name of the search authority and a +database mode. The search authority can be any unique string, but the best practice is to use a +fully qualified name for your content provider +(package name followed by the provider's class name; for example, +"com.example.MySuggestionProvider"). The database mode must include {@link android.content.SearchRecentSuggestionsProvider#DATABASE_MODE_QUERIES} and can optionally include {@link -android.content.SearchRecentSuggestionsProvider#DATABASE_MODE_2LINES}, which will add another column +android.content.SearchRecentSuggestionsProvider#DATABASE_MODE_2LINES}, which adds another column to the suggestions table that allows you to provide a second line of text with each suggestion. For -example:
+example, if you want to provide two lines in each suggestion: +public final static int MODE = DATABASE_MODE_QUERIES | DATABASE_MODE_2LINES;-
In the following section, you'll see how to save both lines of text.
- -Now simply declare the content provider in your application manifest with the same authority -string used in the class (and in the searchable configuration). For example:
+Now declare the content provider in your application manifest with the same authority +string used in your {@link android.content.SearchRecentSuggestionsProvider} class (and in the +searchable configuration). For example:
<application>
<provider android:name=".MySuggestionProvider"
- android:authorities="my.package.authority" />
+ android:authorities="com.example.MySuggestionProvider" />
...
</application>
-In order to populate your collection of recent queries, you need to add each query -received by your searchable Activity to the content provider you've just built. To do this, create -an instance of {@link +
To configure your search dialog to use your suggestions provider, you need to add +the {@code android:searchSuggestAuthority} and {@code android:searchSuggestSelection} attributes to +the {@code <searchable>} element in your searchable configuration file. For example:
+ ++<?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.MySuggestionProvider" + android:searchSuggestSelection=" ?" > +</searchable> ++ +
The value for {@code android:searchSuggestAuthority} should be a fully qualified name for +your content provider that exactly matches the authority used in the content provider (the {@code +AUTHORITY} string in the above example). +
+ +The value for {@code android:searchSuggestSelection} must be a single question mark, preceded by +a space ({@code " ?"}), which is simply a placeholder for the SQLite selection argument (which is +automatically replaced by the query text entered by the user).
+ + + +To populate your collection of recent queries, add each query +received by your searchable Activity to your {@link +android.content.SearchRecentSuggestionsProvider}. To do this, create an instance of {@link android.provider.SearchRecentSuggestions} and call {@link -android.provider.SearchRecentSuggestions#saveRecentQuery(String,String)} each time your searchable -Activity receives a query. For example, here's how you can save the query during your -Activity's {@link android.app.Activity#onCreate(Bundle) onCreate()} method:
+android.provider.SearchRecentSuggestions#saveRecentQuery(String,String) saveRecentQuery()} each time +your searchable Activity receives a query. For example, here's how you can save the query during +your Activity's {@link android.app.Activity#onCreate(Bundle) onCreate()} method:
@Override
@@ -193,24 +203,24 @@ public void onCreate(Bundle savedInstanceState) {
}
-Notice that the {@link android.content.SearchRecentSuggestionsProvider} constructor requires the +
The {@link android.content.SearchRecentSuggestionsProvider} constructor requires the same authority and database mode declared by your content provider.
-The {@link android.provider.SearchRecentSuggestions#saveRecentQuery(String,String)} method takes +
The {@link android.provider.SearchRecentSuggestions#saveRecentQuery(String,String) +saveRecentQuery()} method takes the search query string as the first parameter and, optionally, a second string to include as the -second line of the suggestion. The second parameter is only used if you've enabled two-line mode -for the search suggestions with {@link +second line of the suggestion (or null). The second parameter is only used if you've enabled +two-line mode for the search suggestions with {@link android.content.SearchRecentSuggestionsProvider#DATABASE_MODE_2LINES}. If you have enabled -two-line mode, then the query text will be matched against this second line as well.
- -That's all that's needed to build a recent queries suggestion provider. However, there's one -other important thing to do: provide the ability for the user to clear this search history.
+two-line mode, then the query text is also matched against this second line when the Search Manager +looks for matching suggestions. -To protect the user's privacy, you should always provide a way for the user to clear the recent -query suggestions. To clear the recent queries, simply call {@link +query suggestions. To clear the query history, call {@link android.provider.SearchRecentSuggestions#clearHistory()}. For example:
@@ -219,7 +229,7 @@ SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, suggestions.clearHistory();-
Simply execute this from your choice of a "Clear Search History" menu item, -preference item, or button. You should also provide a confirmation dialog when this is pressed, to +
Execute this from your choice of a "Clear Search History" menu item, +preference item, or button. You should also provide a confirmation dialog to verify that the user wants to delete their search history.
diff --git a/docs/html/guide/topics/search/index.jd b/docs/html/guide/topics/search/index.jd index b2252bbf855eb..78e0be2e3f290 100644 --- a/docs/html/guide/topics/search/index.jd +++ b/docs/html/guide/topics/search/index.jd @@ -13,98 +13,96 @@ page.title=Search -The ability to search is considered to be a core user feature on Android. The user should be able -to search any data that is available to them, whether the content is located on the device or the -Internet. This experience should be seamless and consistent across the entire -system, which is why Android provides a simple search framework to help you provide users with +
Search is a core user feature on Android. Users should be able +to search any data that is available to them, whether the content is located on the device or +the Internet. The search experience should be seamless and consistent across the entire +system, which is why Android provides a search framework to help you provide users with a familiar search dialog and a great search experience.
-
+
+Figure 1. Screenshot of a search dialog with custom +search suggestions.
+Android's search framework provides a user interface in which the user can perform a search and -an interaction layer that communicates with your application. This way, you don't have to build -a search box that the user must find in order to begin a search. Instead, -a custom search dialog will appear at the top of the screen at the user's command. -The search framework will manage the search dialog and when the user executes their search, the -search framework will pass the query text to your application so that your application can begin a -search. The screenshot to the right shows an example of the search dialog (using -search suggestions).
+Android's search framework provides a user interface in which users can perform a search and +an interaction layer that communicates with your application, so you don't have to build +your own search Activity. Instead, a search dialog appears at the top of the screen at the user's +command without interrupting the current Activity.
+ +The search framework manages the life of the search dialog. When users execute a search, the +search framework passes the query text to your application so your application can perform a +search. Figure 1 shows an example of the search dialog with optional search suggestions.
Once your application is set up to use the search dialog, you can:
The following documents will teach you how to use the search dialog in -your application:
+Note: The search framework does not provide APIs to +search your data. To perform a search, you need to use APIs appropriate for your data. For example, +if your data is stored in an SQLite database, you should use the {@link android.database.sqlite} +APIs to perform searches.
+ +The following documents show you how to use the search dialog in your application:
Also, the Searchable Configuration document -provides a reference for the searchable configuration file (though the above -documents also discuss the configuration file in terms of specific behaviors).
- -Note: The search framework does not provide APIs to -perform searches on your data. Performing actual searches is a task that you must accomplish -using APIs appropriate for your data, such as those in {@link android.database.sqlite} -if your data is in an SQLite database.
-When you implement search in your application, you should take steps to protect the user's -privacy whenever possible. Many users consider their activities on the phone, including searches, to -be private information. To protect the user's privacy, you should abide by the following +
When you implement search in your application, take steps to protect the user's +privacy. Many users consider their activities on the phone—including searches—to +be private information. To protect each user's privacy, you should abide by the following principles:
"Personal information" is information that can personally identify your users, such as their -name, email address, billing information, or other data which can be reasonably linked to such -information. If -your application implements search with the assistance of a server, try to avoid sending personal -information along with the search queries. For example, if you are searching for businesses near a -zip code, -you don't need to send the user ID as well — send only the zip code to the server. If you must -send the personal information, you should take steps to avoid logging it. If you must log it, you -should protect that data very carefully and erase it as soon as possible.
+Personal information is any information that can personally identify your users, such as their +names, email addresses, billing information, or other data that can be reasonably linked to such +information. If your application implements search with the assistance of a server, avoid sending +personal information along with the search queries. For example, if you are searching for businesses +near a zip code, +you don't need to send the user ID as well; send only the zip code to the server. If you must +send the personal information, you should not log it. If you must log it, protect that data +very carefully and erase it as soon as possible.
The search framework helps your application provide context-specific suggestions while they type. -Sometimes these -suggestions are based on previous searches, or other actions taken by the user in an earlier -session. A user may not wish for previous searches to be revealed to other users, for instance if -they share their phone with a friend. If your application provides suggestions that can reveal -previous activities, you should implement a "Clear History" menu item, preference, or button. If you -are -using {@link android.provider.SearchRecentSuggestions}, you can simply call its {@link -android.provider.SearchRecentSuggestions#clearHistory()} method. If you are implementing custom -suggestions, you'll need to provide a -similar "clear history" method in your provider that can be invoked by the user.
+The search framework helps your application provide context-specific suggestions while the user +types. Sometimes these +suggestions are based on previous searches or other actions taken by the user in an earlier +session. A user might not wish for previous searches to be revealed to other device users, for +instance, if they share their phone with a friend. If your application provides suggestions that can +reveal previous activities, you should implement the ability for the user to clear the search +history. If you are using {@link android.provider.SearchRecentSuggestions}, you can simply call the +{@link android.provider.SearchRecentSuggestions#clearHistory()} method. If you are implementing +custom suggestions, you'll need to provide a similar "clear history" method in your provider that +the user can execute.
When you want to provide search in your application, the last thing you should have to worry -about is where to put your search box. By using the Android search framework, your application will -reveal a custom search dialog whenever the user requests it. At the -press of a dedicated search key or an API call from your application, the search dialog will -appear at the top of the screen and will automatically show your application icon. An example is -shown in the screenshot below.
+When you want to implement search in your application, the last thing you should have to worry +about is where to put the search box. When you implement search with the Android search framework, +you don't have to. When the user invokes search, a search dialog appears at the top of the screen +with your application icon to the left of the search box. When the user executes the search, your +application receives the query so it can search your application's data. An example of the search +dialog is shown in figure 1.
-This guide will teach you how to set up your application to provide search in a custom search -dialog. In doing so, you will provide a standardized search experience and be able to add -features like voice search and search suggestions.
+This guide shows you how to set up your application to provide search in the search +dialog. When you use the search dialog, you provide a standardized search +experience and can add features such as voice search and search suggestions.
+
+Figure 1. Screenshot of an application's search dialog.
+The Android search framework will manage the search dialog on your behalf; you never need -to draw it or worry about where it is, and your current Activity will not be -interrupted. The {@link android.app.SearchManager} is the component that does this work for -you (hereafter, referred to as "the Search Manager"). It manages the life of the Android search -dialog and will send your application the search query when executed by the user.
+The Android search framework manages the search dialog for your application. You never need +to draw it or worry about where it is, and your Activity is not interrupted when the search dialog +appears. The Search Manager ({@link android.app.SearchManager}) is the component that does this work +for you. It manages the life of the search dialog and sends your application the user's search +query.
-When the user executes a search, the Search Manager will use a specially-formed Intent to pass -the search query to the Activity that you've declared to handle searches. Essentially, all you -need is an Activity that receives this Intent, performs the search, and presents the results. -Specifically, what you need is the following:
+When the user executes a search, the Search Manager creates an {@link android.content.Intent} to +pass the search query to the Activity that you've declared to handle searches. Basically, all you +need is an Activity that receives the search Intent, performs the search, and presents the results. +Specifically, you need the following:
The searchable configuration is an XML file that defines several settings for the Android search +
The searchable configuration is an XML file that defines several settings for the search dialog in your application. This file is traditionally named {@code searchable.xml} and must be saved in the {@code res/xml/} project directory.
@@ -94,45 +107,61 @@ or more attributes that configure your search dialog. For example:<?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" - android:label="@string/app_label" > + android:label="@string/app_label" + android:hint="@string/search_hint" > </searchable>-
This is the minimum configuration required in order to provide the search dialog. The {@code -android:label} attribute is the only required attribute and points to a string resource, which -should normally be the same as the application. (Although it's required, this -label isn't actually shown to the user until you enable suggestions for Quick Search Box.)
+The {@code android:label} attribute is the only required attribute and points to a string +resource, which should be the same as the application name. This label isn't actually visible to the +user until you enable suggestions for Quick Search Box, at which point, this label is visible in the +list of Searchable items in the system Settings.
-There are several other attributes accepted by the {@code <searchable>} element. Most of -which apply only when configuring features such as search suggestions and voice -search. However, we recommend that you always include the {@code android:hint} attribute, which -specifies a string resource for the text to display in the search dialog's text box before the user -enters their query—it provides important clues to the user about what they can search.
+Though it's not required, we recommend that you always include the {@code android:hint} +attribute, which provides a hint string in the search dialog's text box before the user +enters their query. The hint is important because it provides important clues to users about what +they can search.
Tip: For consistency among other Android applications, you should format the string for {@code android:hint} as "Search <content-or-product>". For example, "Search songs and artists" or "Search YouTube".
-Next, you'll hook this configuration into your application.
+The {@code <searchable>} element accepts several other attributes. Most attributes apply +only when configuring features such as search suggestions and voice search.
+ +For more details about the searchable configuration file, see the Searchable Configuration +reference.
+When the user executes a search from the search dialog, the Search Manager will send -your searchable {@link android.app.Activity} the search query with the {@link -android.content.Intent#ACTION_SEARCH} {@link android.content.Intent}. Your searchable Activity will -then search your data and present the results.
+When the user executes a search from the search dialog, the Search Manager takes the query +and sends it to your searchable {@link android.app.Activity} in the {@link +android.content.Intent#ACTION_SEARCH} {@link android.content.Intent}. Your searchable Activity +then searches your data using the query and presents the results to the user.
+ +In order for the Search Manager to know where to deliver the search query, you must declare your +searchable Activity in the Android manifest file.
If you don't have one already, create an {@link android.app.Activity} that will be used to -perform searches, then declare it to -accept the {@link android.content.Intent#ACTION_SEARCH} {@link android.content.Intent} and apply the -searchable configuration. To do so, you need to add an {@code -<intent-filter>} element and a {@code <meta-data>} element to the -appropriate {@code <activity>} element in your manifest file. For example:
+If you don't have one already, create an {@link android.app.Activity} that performs +searches and present search results. To set up this Activity as your searchable Activity:
+For example:
<application ... >
@@ -147,29 +176,27 @@ appropriate {@code <activity>} element in your manifest file. For example:
</application>
-The {@code android:name} attribute in the {@code <meta-data>} element must be defined with -{@code "android.app.searchable"} and the {@code android:resource} attribute value must be a -reference to the searchable configuration file saved in {@code res/xml} (in this example, it +
The {@code <meta-data>} element must include the {@code android:name} attribute with a +value of {@code "android.app.searchable"} and the {@code android:resource} attribute with a +reference to the searchable configuration file (in this example, it refers to the {@code res/xml/searchable.xml} file).
-If you're wondering why the {@code -<intent-filter>} does not include a {@code <category>} with the {@code DEFAULT} -value, it's because the Intent that is delivered to this Activity when a search is executed will -explicitly define this Activity as the component for the Intent (which the Search Manager knows -from the searcahble meta-data declared for the Activity).
+Note: The {@code <intent-filter>} does not need a {@code <category>} with the +{@code DEFAULT} value, because the Search Manager delivers the {@link +android.content.Intent#ACTION_SEARCH} Intent explicitly to your searchable Activity by name.
-Be aware that the search dialog will not be available from within every -Activity of your application, by default. Rather, the search dialog will be presented to -users only when they +
The search dialog is not, by default, available from every Activity of your +application. Rather, the search dialog is presented to users only when they invoke search from a searchable context of your application. A searchable context is any Activity for which you have declared searchable meta-data in the manifest file. For example, the searchable Activity itself (declared in the manifest snippet above) is -a searchable context because it contains searchable meta-data that defines the +a searchable context because it includes meta-data that defines the searchable configuration. Any other Activity in your application is not a searchable context, by -default, and thus, will not reveal the search dialog. You probably do want the -search dialog to be available from every Activity in your application, so this can be easily -fixed.
+default, and thus, does not reveal the search dialog. However, you probably do want the search +dialog available from your other activities (and to launch the searchable Activity when the user +executes a search). You can do exactly that.If you want all of your activities to provide the search dialog, add another {@code <meta-data>} element inside the {@code @@ -187,9 +214,9 @@ default searchable Activity. For example:
</activity> <activity android:name=".AnotherActivity" ... > </activity> - <!-- this one declares the searchable Activity for the whole app --> - <meta-data android:name="android.app.default_searchable" - android:value=".MySearchableActivity" /> + <!-- declare the default searchable Activity for the whole app --> + <meta-data android:name="android.app.default_searchable" + android:value=".MySearchableActivity" /> ... </application> @@ -199,28 +226,34 @@ default searchable Activity. For example: which it is placed (which, in this case, is the entire application). The searchable Activity to use is specified with the {@code android:value} attribute. All other activities in the application, such as {@code AnotherActivity}, are now considered a searchable context and can invoke -the search dialog. When a search is executed, {@code MySearchableActivity} will -be launched to handle the search query. +the search dialog. When a search is executed, {@code MySearchableActivity} is launched to handle +the search query. -Notice that this allows you to control which activities provide search at a more granular level. -To specify only an individual Activity as a searchable context, simply place the {@code +
You can also control which activities provide search at a more granular level. +To specify only an individual Activity as a searchable context, place the {@code <meta-data>} with the {@code "android.app.default_searchable"} name inside the respective {@code <activity>} -element (rather than inside the {@code <application>}). And, while it is uncommon, you can -even create more than one searchable Activity and provide each one in different contexts of your +element (rather than inside the {@code <application>} element). While uncommon, you +can also create more than one searchable Activity and provide each one in different contexts of your application, either by declaring a different searchable Activity in each {@code <activity>} -element, or declaring a default searchable Activity for the entire application and then overriding -it with a different {@code <meta-data>} element inside certain activities.
+element, or by declaring a default searchable Activity for the entire application and then +overriding it with a {@code <meta-data>} element inside certain activities. (You might do +this if you want to search different sets of data that cannot be handled by the same +searchable Activity, depending on the currently open Activity.)Once your Activity is declared searchable, performing the actual search involves three steps: -receiving the query, searching your data, and presenting the results.
+Once you have declared your searchable Activity, performing a search for the user involves +three steps:
+ -Traditionally, your search results should be presented in a {@link android.widget.ListView} -(assuming that our results are text-based), so -you may want your searchable Activity to extend {@link android.app.ListActivity}, which +
Traditionally, your search results should be presented in a {@link android.widget.ListView}, so +you might want your searchable Activity to extend {@link android.app.ListActivity}, which provides easy access to {@link android.widget.ListView} APIs. (See the List View Tutorial for a simple {@link android.app.ListActivity} sample.)
@@ -228,12 +261,12 @@ href="{@docRoot}resources/tutorials/views/hello-listview.html">List View TutoriaWhen a search is executed from the search dialog, your searchable Activity will be opened -with the {@link android.content.Intent#ACTION_SEARCH} {@link android.content.Intent}, which carries -the search query in the -{@link android.app.SearchManager#QUERY QUERY} extra. All you need to do is check for -this Intent and extract the string. For example, here's how you can get the query when your -Activity launches:
+When a user executes a search from the search dialog, the Search Manager sends the {@link +android.content.Intent#ACTION_SEARCH} {@link android.content.Intent} to your searchable Activity. +This Intent carries the search query in the +{@link android.app.SearchManager#QUERY QUERY} string extra. You must check for +this Intent when the Activity starts and extract the string. For example, here's how you can get the +query when your Activity starts:
@Override @@ -258,22 +291,21 @@ is done.Searching your data
-The process of storing and searching your data is a process that's unique to your application. -There are many ways that you might do this and discussing all options is beyond the scope of -this document. This guide will not teach you how to store your data and search it; this -is something you must carefully consider in terms of your needs and your data. However, here are -some tips you may be able to apply:
+The process of storing and searching your data is unique to your application. +You can store and search your data in many ways, but this guide does not show you how to store your +data and search it. Storing and searching your data is something you should carefully consider in +terms of your needs and your data. However, here are some tips you might be able to apply:
An Adapter will bind individual items from a set of data into individual {@link +
An Adapter binds individual items from a set of data into individual {@link android.view.View} objects. When the Adapter is applied to a {@link android.widget.ListView}, the Views are injected as individual items of the list. {@link android.widget.Adapter} is simply an interface, so implementations such as {@link android.widget.CursorAdapter} (for binding data from a {@link android.database.Cursor}) are needed. If none of the existing implementations work for your data, then you should implement your own from -{@link android.widget.BaseAdapter}. Install the SDK Samples package for API Level 4 to see a -version of the Searchable Dictionary that creates a custom BaseAdapter.
+{@link android.widget.BaseAdapter}. Install the SDK Samples package for API Level 4 to see the +original version of the Searchable Dictionary, which creates a custom BaseAdapter.Regardless of where your data lives and how you search it, we recommend that you return search results to your searchable Activity with an {@link android.widget.Adapter}. This way, you can easily present all the search results in a {@link android.widget.ListView}. If your data comes from a -SQLite database query, then you can easily apply your results to a {@link android.widget.ListView} +SQLite database query, then you can apply your results to a {@link android.widget.ListView} using a {@link android.widget.CursorAdapter}. If your data comes in some other type of format, then you can create an extension of the {@link android.widget.BaseAdapter}.
Presenting your search results is mostly a UI detail and not something covered by the search -framework APIs. However, a simple solution is to create your searchable Activity to extend {@link -android.app.ListActivity} and then call {@link +
Presenting your search results is mostly a UI detail that is not handled by the search APIs. +However, one option is to create your searchable Activity to extend {@link +android.app.ListActivity} and call {@link android.app.ListActivity#setListAdapter(ListAdapter)}, passing it an {@link -android.widget.Adapter} that is bound to your data. This will automatically project all the +android.widget.Adapter} that is bound to your data. This injects all the results into the Activity {@link android.widget.ListView}.
For more help presenting your results, see the {@link android.app.ListActivity} @@ -316,29 +348,27 @@ documentation.
Also see the Searchable Dictionary sample -application for an a complete demonstration of how to search an SQLite database and use an -{@link android.widget.Adapter} to provide resuls in a {@link android.widget.ListView}.
+for an a complete demonstration of how to search an SQLite database and use an +{@link android.widget.Adapter} to provide results in a {@link android.widget.ListView}. +Once you have a searchable Activity in place, invoking the search dialog so the user can -submit a -query is easy. Many Android devices provide a dedicated search key and when it is pressed while the -user is within a searchable context of your application, the search dialog will be revealed. -However, -you should never assume that a search key is available on the user's device and should always -provide a search button in your UI that will invoke search.
+Once you have a searchable Activity, invoking the search dialog is easy. Many Android +devices provide a dedicated SEARCH key, which reveals the search dialog when the user presses it +from a searchable context of your application. However, you should not assume that a SEARCH +key is available on the user's device and should always provide a search button in your UI that +invokes search.
-To invoke search from your Activity, simply call {@link -android.app.Activity#onSearchRequested()}.
+To invoke search from your Activity, call {@link android.app.Activity#onSearchRequested()}.
-For example, you should provide a menu item in your For instance, you should provide a menu item in your Options Menu or a button in your UI to -invoke search with this method. For your convenience, this search_icons.zip file includes icons for -medium and high density screens, which you can use for your menu item or button (low density -screens will automatically scale-down the hdpi image by one half).
+medium and high density screens, which you can use for your search menu item or button (low density +screens automatically scale-down the hdpi image by one half). -You can also enable "type-to-search" functionality in your Activity by calling {@link -android.app.Activity#setDefaultKeyMode(int) setDefaultKeyMode}({@link -android.app.Activity#DEFAULT_KEYS_SEARCH_LOCAL}). When this is enabled and the user begins typing on -the keyboard, search will automatically be -invoked and the keystrokes will be inserted in the search dialog. Be sure to enable this mode -during your Activity {@link android.app.Activity#onCreate(Bundle) onCreate()} method.
+You can also enable "type-to-search" functionality, which reveals the search dialog when the +user starts typing on the keyboard and the keystrokes are inserted into the search dialog. You can +enable type-to-search in your Activity by calling +{@link android.app.Activity#setDefaultKeyMode(int) setDefaultKeyMode}({@link +android.app.Activity#DEFAULT_KEYS_SEARCH_LOCAL}) during your Activity's +{@link android.app.Activity#onCreate(Bundle) onCreate()} method.
-The search dialog behaves like a {@link android.app.Dialog} that floats at the top of the -screen. It -does not cause any change in the Activity stack, so no life-cycle methods (such as {@link -android.app.Activity#onPause()}) will -be called. All that happens is your Activity loses input focus as it is given to the search dialog. +
The search dialog is a {@link android.app.Dialog} that floats at the top of the +screen. It does not cause any change in the Activity stack, so when the search dialog appears, no +lifecycle methods for the currently open Activity (such as {@link +android.app.Activity#onPause()}) are called. Your Activity just loses input focus as it is given to +the search dialog.
-If you want to be notified when search is invoked, simply override the {@link -android.app.Activity#onSearchRequested()} method. When this is called, you can do any work you may -want to do when your Activity looses input focus (such as pause animations). But unless you are -Passing Search Context Data (discussed above), you should always -call the super class implementation. For example:
+If you want to be notified when search is invoked, override the {@link +android.app.Activity#onSearchRequested()} method. When the system calls this method, you can do any +work you want to when your Activity looses input focus to the search dialog (such as pause +animations). Unless you are passing search context data +(discussed below), you should end the method by calling the super class implementation. For +example:
@Override
@@ -377,35 +408,37 @@ public boolean onSearchRequested() {
}
-If the user cancels search by pressing the device Back key, the Activity in which search was -invoked will re-gain input focus. You can register to be notified when the search dialog is -closed with {@link android.app.SearchManager#setOnDismissListener(SearchManager.OnDismissListener)} -and/or {@link android.app.SearchManager#setOnCancelListener(SearchManager.OnCancelListener)}. You -should normally only need to register the {@link android.app.SearchManager.OnDismissListener -OnDismissListener}, because this is called every time that the search dialog is closed. The {@link +
If the user cancels search by pressing the BACK key, the Activity in which search was +invoked re-gains input focus. You can register to be notified when the search dialog is +closed with {@link android.app.SearchManager#setOnDismissListener(SearchManager.OnDismissListener) +setOnDismissListener()} +and/or {@link android.app.SearchManager#setOnCancelListener(SearchManager.OnCancelListener) +setOnCancelListener()}. You +should need to register only the {@link android.app.SearchManager.OnDismissListener +OnDismissListener}, because it is called every time the search dialog closes. The {@link android.app.SearchManager.OnCancelListener OnCancelListener} only pertains to events in which the -user explicitly left the search dialog, so it is not called when a search is executed (in which +user explicitly exited the search dialog, so it is not called when a search is executed (in which case, the search dialog naturally disappears).
-If the current Activity is not the searchable Activity, then the normal Activity life-cycle -events will be triggered once the user executes a search (the current Activity will receive {@link +
If the current Activity is not the searchable Activity, then the normal Activity lifecycle +events are triggered once the user executes a search (the current Activity receives {@link android.app.Activity#onPause()} and so forth, as described in Application Fundamentals). If, however, the current Activity is the searchable Activity, then one of two -things will happen:
+things happens: -
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -430,28 +463,30 @@ private void handleIntent(Intent intent) {
Compared to the example code in the section about Performing a
Search, all the code to handle the
-search Intent has been moved outside the {@link android.app.Activity#onCreate(Bundle)
-onCreate()} method so it can also be executed from {@link android.app.Activity#onNewIntent(Intent)
-onNewIntent()}.
-It's important to note that when {@link android.app.Activity#onNewIntent(Intent)} is
-called, the Activity has not been restarted, so the {@link android.app.Activity#getIntent()} method
-will still return the Intent that was first received with {@link
-android.app.Activity#onCreate(Bundle) onCreate()}. This is why {@link
-android.app.Activity#setIntent(Intent)} is called inside {@link
-android.app.Activity#onNewIntent(Intent)} (just in case you call {@link
-android.app.Activity#getIntent()} at a later time).
+search Intent is now in the {@code handleIntent()} method, so that both {@link
+android.app.Activity#onCreate(Bundle)
+onCreate()} and {@link android.app.Activity#onNewIntent(Intent) onNewIntent()} can execute it.
+
+When the system calls {@link android.app.Activity#onNewIntent(Intent)}, the Activity has
+not been restarted, so the {@link android.app.Activity#getIntent()} method
+returns the same Intent that was received with {@link
+android.app.Activity#onCreate(Bundle) onCreate()}. This is why you should call {@link
+android.app.Activity#setIntent(Intent)} inside {@link
+android.app.Activity#onNewIntent(Intent)} (so that the Intent saved by the Activity is updated in
+case you call {@link android.app.Activity#getIntent()} in the future).
This second scenario is normally ideal, because the chances are good that once a search is -completed, the user will perform additional searches and it's a bad experience if your application -piles multiple instances of the searchable Activity on the stack. So we recommend that you set your -searchable Activity to "singleTop" launch mode in the application manifest. For example:
+The second scenario using "singleTop" launch mode is usually ideal, because chances are good that +once a search is done, the user will perform additional searches and it's a bad experience if your +application creates multiple instances of the searchable Activity. So, we recommend that you set +your searchable Activity to "singleTop" launch mode in the application +manifest. For example:
<activity android:name=".MySearchableActivity"
- android:launchMode="singleTop" >
+ android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
@@ -461,19 +496,20 @@ searchable Activity to "singleTop" launch mode in the application manifest. For
+
In order to refine your search criteria, you may want to provide some additional -data to your searchable Activity when a search is executed. For instance, when you search your data, -you may want to filter results based on more than just the search query text. In a simple -case, you could just make your refinements inside the searchable Activity, for every search made. -If, however, your -search criteria may vary from one searchable context to another, then you can pass whatever data is -necessary to refine your search in the {@link android.app.SearchManager#APP_DATA} Bundle, which is -included in the {@link android.content.Intent#ACTION_SEARCH} Intent.
+To refine your search criteria from the current Activity instead of depending only on the user's +search query, you can provide additional data in the Intent that the Search Manager sends to your +searchable Activity. In a simple case, you can make your refinements inside the searchable +Activity, for every search made, but if your +search criteria varies from one searchable context to another, then you can pass whatever data +is necessary to refine your search in the {@link android.app.SearchManager#APP_DATA} {@link +android.os.Bundle}, which is included in the {@link android.content.Intent#ACTION_SEARCH} +Intent.
-To pass this kind of data to your searchable Activity, you need to override {@link -android.app.Activity#onSearchRequested()} method for the Activity in which search will be invoked. +
To pass this kind of data to your searchable Activity, override {@link +android.app.Activity#onSearchRequested()} method for the Activity in which search can be invoked. For example:
@@ -487,56 +523,54 @@ public boolean onSearchRequested() {
Returning "true" indicates that you have successfully handled this callback event. Then in your -searchable Activity, you can extract this data from the {@link +searchable Activity, you can extract the data placed inside {@code appdata} from the {@link android.app.SearchManager#APP_DATA} {@link android.os.Bundle} to refine the search. For example:
- Bundle appData = getIntent().getBundleExtra(SearchManager.APP_DATA);
- if (appData != null) {
- boolean jargon = appData.getBoolean(MySearchableActivity.JARGON);
- }
+Bundle appData = getIntent().getBundleExtra(SearchManager.APP_DATA);
+if (appData != null) {
+ boolean jargon = appData.getBoolean(MySearchableActivity.JARGON);
+}
-Note: You should never call the {@link +
Caution: Never call the {@link android.app.Activity#startSearch(String,boolean,Bundle,boolean) startSearch()} method from outside -the {@link android.app.Activity#onSearchRequested()} callback method. When you want to invoke the -search dialog, always call {@link android.app.Activity#onSearchRequested()} so that custom -implementations (such as the addition of {@code appData}, in the above example) can be accounted -for.
+the {@link android.app.Activity#onSearchRequested()} callback method. To invoke the search dialog +in your Activity, always call {@link android.app.Activity#onSearchRequested()}. Otherwise, {@link +android.app.Activity#onSearchRequested()} is not called and customizations (such as the addition of +{@code appData} in the above example) are missed.You can easily add voice search functionality to your search dialog by adding the {@code -android:voiceSearchMode} attribute to your searchable configuration. This will add a voice search -button in the search dialog that, when clicked, will launch a voice prompt. When the user -has finished speaking, the transcribed search query will be sent to your searchable +
You can add voice search functionality to your search dialog by adding the {@code +android:voiceSearchMode} attribute to your searchable configuration. This adds a voice search +button in the search dialog that launches a voice prompt. When the user +has finished speaking, the transcribed search query is sent to your searchable Activity.
-To enable voice search for your activity, add the {@code android:voiceSearchMode} -attribute to your searchable configuration. For example:
+For example:
<?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:voiceSearchMode="showVoiceSearchButton|launchRecognizer" >
+ android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" >
</searchable>
The value {@code showVoiceSearchButton} is required to enable voice search, while the second value, {@code launchRecognizer}, specifies that the voice search button -should launch a recognizer that returns the transcribed text to the searchable Activity. This is -how most applications should declare this attribute.
+should launch a recognizer that returns the transcribed text to the searchable Activity. -There are some additional attributes you can provide to specify the voice search behavior, such +
You can provide additional attributes to specify the voice search behavior, such as the language to be expected and the maximum number of results to return. See the Searchable Configuration for more information about the +href="searchable-config.html">Searchable Configuration reference for more information about the available attributes.
Note: Carefully consider whether voice search is appropriate for -your application. All searches performed with the voice search button will be immediately sent to -your searchable Activity without a chance for the user to review the transcribed query. Be sure to -sufficiently test the voice recognition and ensure that it understands the types of queries that -the user will submit inside your application.
+your application. All searches performed with the voice search button are immediately sent to +your searchable Activity without a chance for the user to review the transcribed query. Sufficiently +test the voice recognition and ensure that it understands the types of queries that +the user might submit inside your application. diff --git a/docs/html/guide/topics/search/searchable-config.jd b/docs/html/guide/topics/search/searchable-config.jd index 71566de3cb207..2aa2db6219cb1 100644 --- a/docs/html/guide/topics/search/searchable-config.jd +++ b/docs/html/guide/topics/search/searchable-config.jd @@ -14,18 +14,18 @@ parent.link=index.html -In order to utilize the Android search framework and provide a custom search dialog, your +
To utilize the Android search framework and provide a custom search dialog, your application must provide a search configuration in the form of an XML resource. This document describes the search configuration XML -in terms of its syntax and usage. For a more complete discussion about how to implement search -features for your application, see the companion documents about Search.
res/xml/filename.xmlattributes:
android:labelandroid:includeInGlobalSearch "true", in which case, this label is used to identify
+<application>} manifest element. This label is only visible to the user when you set
+android:includeInGlobalSearch to "true", in which case, this label is used to identify
your application as a searchable item in the system's search settings.android:hintandroid:searchMode| Value | Description | ||
|---|---|---|---|
"queryRewriteFromData" |
- If set, this causes the suggestion column - {@link android.app.SearchManager#SUGGEST_COLUMN_INTENT_DATA} to be considered as the -text for suggestion query - rewriting. This should only be used when the values in - {@link android.app.SearchManager#SUGGEST_COLUMN_INTENT_DATA} are suitable for user -inspection and editing - - typically, HTTP/HTTPS Uri's. | +"queryRewriteFromText" |
+ Use the value from the {@link android.app.SearchManager#SUGGEST_COLUMN_TEXT_1} +colum to rewrite the query text in the search dialog. |
"queryRewriteFromText" |
- If set, this causes the suggestion - column {@link android.app.SearchManager#SUGGEST_COLUMN_TEXT_1} to be considered as the -text for suggestion query - rewriting. This should be used for suggestions in which no query - text is provided and the {@link android.app.SearchManager#SUGGEST_COLUMN_INTENT_DATA} -values are not suitable - for user inspection and editing. | +"queryRewriteFromData" |
+ Use the value from the + {@link android.app.SearchManager#SUGGEST_COLUMN_INTENT_DATA} column to rewrite the +query text in the search dialog. This should only be used when the values in + {@link android.app.SearchManager#SUGGEST_COLUMN_INTENT_DATA} are suitable for user +inspection and editing, typically HTTP URI's. |
For more information, see the discussion about rewriting the query text in Adding Custom Suggestions.
android:searchButtonTextandroid:inputTypeandroid:imeOptionsIf you have defined a content provider to generate search suggestions, you need to - define additional attributes in order to configure communications with the Content - Provider. When providing search suggestions, you'll need some of the following + define additional attributes that configure communications with the content + provider. When providing search suggestions, you need some of the following {@code <searchable>} attributes:
android:searchSuggestAuthorityandroid:searchSuggestPathandroid:searchSuggestSelectionandroid:searchSuggestIntentActionandroid:searchSuggestIntentDataandroid:searchSuggestThresholdFor more information about the above attributes for search suggestions, see the guides for Adding Recent Query Suggestions and Adding Custom Suggestions.
-Beyond providing search suggestions while using your application's search dialog, you - can also configure your search suggestions to be made available to Quick Search Box, - which will allow users so receive search suggestions from your application content from outside - your application. When providing search suggestions to Quick Search Box, you'll need some of the + +
To make your custom search suggestions available to Quick Search Box, you need some of the following {@code <searchable>} attributes:
android:includeInGlobalSearchandroid:searchSettingsDescriptionandroid:queryAfterZeroResultsTo enable voice search for your search dialog, you'll need some of the following {@code <searchable>} attributes:
android:voiceSearchMode| Value | Description | |
|---|---|---|
"showVoiceSearchButton" |
- Display a voice search button. This only - takes effect if voice search is available on the device. If set, then either - {@code "launchWebSearch"} or {@code "launchRecognizer"} must also be set + | Display a voice search button, if voice search is available on the device. If set, +then either {@code "launchWebSearch"} or {@code "launchRecognizer"} must also be set (separated by the pipe | character). |
"launchWebSearch" |
- The voice search button will take the user directly - to a built-in voice web search activity. Most applications will not use this flag, as - it will take the user away from the Activity in which search was invoked. | +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. |
"launchRecognizer" |
- The voice search button will take + | The voice search button takes the user directly to a built-in voice recording activity. This Activity - will prompt the user to speak, transcribe the spoken text, and forward the resulting - query text to the searchable Activity, just as if the user had typed it into the + 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. |
android:voiceLanguageModel"free_form""web_search"Also see {@link android.speech.RecognizerIntent#EXTRA_LANGUAGE_MODEL} for more information.
android:voicePromptTextandroid:voiceLanguageandroid:voiceMaxResults<actionkey>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.
attributes:
android:keycodeandroid:queryActionMsgandroid:suggestActionMsgandroid:suggestActionMsgColumnFirst, 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 search manager will look at your suggestion cursor, - using the string provided here in order to select your action message column, and - then select the action message string from the cursor. That string will be added to the - Intent that is passed to your searchable Activity (using the action you've defined for - suggestions). To examine the string, use {@link +column in this attribute. The Search Manager 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 Search Manager passes to your searchable Activity (using the action you've +defined for suggestions). To examine the string, use {@link android.content.Intent#getStringExtra getStringExtra(SearchManager.ACTION_MSG)}. If the data -does not exist for the selected suggestion, the action key will be ignored.