Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public class

SearchRecentSuggestionsProvider

extends ContentProvider
java.lang.Object
   ↳ android.content.ContentProvider
     ↳ android.content.SearchRecentSuggestionsProvider

Class Overview

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.

  • Implement and test query search, as described in 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.)
  • Create a Content Provider within your application by extending 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.
  • Create a manifest entry describing your provider. Typically this would be as simple as adding the following lines:
              <!-- Content provider for search suggestions -->
         <provider android:name="YourSuggestionProviderClass"
                   android:authorities="your.suggestion.authority" />
             
  • Please note that you do not instantiate this content provider directly from within your code. This is done automatically by the system Content Resolver, when the search dialog looks for suggestions.
  • In order for the Content Resolver to do this, you must update your searchable activity's XML configuration file with information about your content provider. The following additions are usually sufficient:
              android:searchSuggestAuthority="your.suggestion.authority"
         android:searchSuggestSelection=" ? "
             
  • In your searchable activities, capture any user-generated queries and record them for future searches by calling SearchRecentSuggestions.saveRecentQuery() .

Developer Guides

For information about using search suggestions in your application, read the Search developer guide.

Summary

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.
[Expand]
Inherited Constants
From interface 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.
[Expand]
Inherited Methods
From class android.content.ContentProvider
From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.content.ComponentCallbacks2

Constants

public static final int DATABASE_MODE_2LINES

Added in API level 1

This mode bit configures the database to include a 2nd annotation line with each entry. optional

Constant Value: 2 (0x00000002)

public static final int DATABASE_MODE_QUERIES

Added in API level 1

This mode bit configures the database to record recent queries. required

Constant Value: 1 (0x00000001)

Public Constructors

public SearchRecentSuggestionsProvider ()

Added in API level 1

Public Methods

public int delete ( Uri uri, String selection, String[] selectionArgs)

Added in API level 1

This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.

Parameters
uri The full URI to query, including a row ID (if a specific record is requested).
selection An optional restriction to apply to rows when deleting.
Returns
  • The number of rows affected.

public String getType ( Uri uri)

Added in API level 1

This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.

Parameters
uri the URI to query.
Returns
  • a MIME type string, or null if there is no type.

public Uri insert ( Uri uri, ContentValues values)

Added in API level 1

This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.

Parameters
uri The content:// URI of the insertion request. This must not be null .
values A set of column_name/value pairs to add to the database. This must not be null .
Returns
  • The URI for the newly inserted item.

public boolean onCreate ()

Added in API level 1

This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.

Returns
  • true if the provider was successfully loaded, false otherwise

public Cursor query ( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)

Added in API level 1

This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.

Parameters
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 The list of columns to put into the cursor. If null all columns are included.
selection A selection criteria to apply when filtering rows. If null then all rows are included.
selectionArgs 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 How the rows in the cursor should be sorted. If null then the provider is free to define the sort order.
Returns
  • a Cursor or null .

public int update ( Uri uri, ContentValues values, String selection, String[] selectionArgs)

Added in API level 1

This method is provided for use by the ContentResolver. Do not override, or directly call from your own code.

Parameters
uri The URI to query. This can potentially have a record ID if this is an update request for a specific record.
values A set of column_name/value pairs to update in the database. This must not be null .
selection An optional filter to match rows to update.
Returns
  • the number of rows affected.

Protected Methods

protected void setupSuggestions ( String authority, int mode)

Added in API level 1

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 This must match the authority that you've declared in your manifest.
mode 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.