public class SearchRecentSuggestionsProvider
extends ContentProvider
java.lang.Object | ||
↳ | android.content.ContentProvider | |
↳ | android.content.SearchRecentSuggestionsProvider |
This superclass can be used to create a simple search suggestions provider for your application. It creates suggestions (as the user types) based on recent queries and/or recent views.
In order to use this class, you must do the following.
SearchManager
. (This provider will send any suggested queries via the standard ACTION_SEARCH
Intent, which you'll already support once you have implemented and tested basic searchability.)SearchRecentSuggestionsProvider
. The class you create will be very simple - typically, it will have only a constructor. But the constructor has a very important responsibility: When it calls setupSuggestions(String, int)
, it configures the provider to match the requirements of your searchable activity.<!-- Content provider for search suggestions --> <provider android:name="YourSuggestionProviderClass" android:authorities="your.suggestion.authority" />
android:searchSuggestAuthority="your.suggestion.authority" android:searchSuggestSelection=" ? "
SearchRecentSuggestions.saveRecentQuery()
.For information about using search suggestions in your application, read the Search developer guide.
See also:
Constants |
|
---|---|
int |
DATABASE_MODE_2LINES This mode bit configures the database to include a 2nd annotation line with each entry. |
int |
DATABASE_MODE_QUERIES This mode bit configures the database to record recent queries. |
Inherited constants |
---|
![]() android.content.ComponentCallbacks2
|
Public constructors |
|
---|---|
SearchRecentSuggestionsProvider() |
Public methods |
|
---|---|
int |
delete(Uri uri, String selection, String[] selectionArgs) This method is provided for use by the ContentResolver. |
String |
getType(Uri uri) This method is provided for use by the ContentResolver. |
Uri |
insert(Uri uri, ContentValues values) This method is provided for use by the ContentResolver. |
boolean |
onCreate() This method is provided for use by the ContentResolver. |
Cursor |
query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) This method is provided for use by the ContentResolver. |
int |
update(Uri uri, ContentValues values, String selection, String[] selectionArgs) This method is provided for use by the ContentResolver. |
Protected methods |
|
---|---|
void |
setupSuggestions(String authority, int mode) In order to use this class, you must extend it, and call this setup function from your constructor. |
Inherited methods |
|
---|---|
![]() android.content.ContentProvider
|
|
![]() java.lang.Object
|
|
![]() android.content.ComponentCallbacks2
|
|
![]() android.content.ComponentCallbacks
|
int DATABASE_MODE_2LINES
This mode bit configures the database to include a 2nd annotation line with each entry. optional
See also:
Constant Value: 2 (0x00000002)
int DATABASE_MODE_QUERIES
This mode bit configures the database to record recent queries. required
See also:
Constant Value: 1 (0x00000001)
int delete (Uri uri, String selection, String[] selectionArgs)
This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.
Parameters | |
---|---|
uri |
Uri : The full URI to query, including a row ID (if a specific record is requested). |
selection |
String : An optional restriction to apply to rows when deleting. |
selectionArgs |
String
|
Returns | |
---|---|
int |
The number of rows affected. |
String getType (Uri uri)
This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.
Parameters | |
---|---|
uri |
Uri : the URI to query. |
Returns | |
---|---|
String |
a MIME type string, or null if there is no type. |
Uri insert (Uri uri, ContentValues values)
This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.
Parameters | |
---|---|
uri |
Uri : The content:// URI of the insertion request. This must not be null . |
values |
ContentValues : A set of column_name/value pairs to add to the database. This must not be null . |
Returns | |
---|---|
Uri |
The URI for the newly inserted item. |
boolean onCreate ()
This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.
Returns | |
---|---|
boolean |
true if the provider was successfully loaded, false otherwise |
Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.
Parameters | |
---|---|
uri |
Uri : The URI to query. This will be the full URI sent by the client; if the client is requesting a specific record, the URI will end in a record number that the implementation should parse and add to a WHERE or HAVING clause, specifying that _id value. |
projection |
String : The list of columns to put into the cursor. If null all columns are included. |
selection |
String : A selection criteria to apply when filtering rows. If null then all rows are included. |
selectionArgs |
String : You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings. |
sortOrder |
String : How the rows in the cursor should be sorted. If null then the provider is free to define the sort order. |
Returns | |
---|---|
Cursor |
a Cursor or null . |
int update (Uri uri, ContentValues values, String selection, String[] selectionArgs)
This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.
Parameters | |
---|---|
uri |
Uri : The URI to query. This can potentially have a record ID if this is an update request for a specific record. |
values |
ContentValues : A set of column_name/value pairs to update in the database. This must not be null . |
selection |
String : An optional filter to match rows to update. |
selectionArgs |
String
|
Returns | |
---|---|
int |
the number of rows affected. |
void setupSuggestions (String authority, int mode)
In order to use this class, you must extend it, and call this setup function from your constructor. In your application or activities, you must provide the same values when you create the SearchRecentSuggestions
helper.
Parameters | |
---|---|
authority |
String : This must match the authority that you've declared in your manifest. |
mode |
int : You can use mode flags here to determine certain functional aspects of your database. Note, this value should not change from run to run, because when it does change, your suggestions database may be wiped. |
See also: