Android
android.provider
public class

android.provider.SearchRecentSuggestions

java.lang.Object
android.provider.SearchRecentSuggestions

This is a utility class providing access to SearchRecentSuggestionsProvider.

Unlike some utility classes, this one must be instantiated and properly initialized, so that it can be configured to operate with the search suggestions provider that you have created.

Typically, you will do this in your searchable activity, each time you receive an incoming ACTION_SEARCH Intent. The code to record each incoming query is as follows:

      SearchSuggestions suggestions = new SearchSuggestions(this, 
              MySuggestionsProvider.AUTHORITY, MySuggestionsProvider.MODE);
      suggestions.saveRecentQuery(queryString, null);
 

For a working example, see SearchSuggestionSampleProvider and SearchQueryResults in samples/ApiDemos/app.

Summary

Constants

      Value  
String[]  QUERIES_PROJECTION_1LINE  This is the database projection that can be used to view saved queries, when configured for one-line operation.     
String[]  QUERIES_PROJECTION_2LINE  This is the database projection that can be used to view saved queries, when configured for two-line operation.     
int  QUERIES_PROJECTION_DATE_INDEX  Index into the provided query projections.  0x00000001 
int  QUERIES_PROJECTION_DISPLAY1_INDEX  Index into the provided query projections.  0x00000003 
int  QUERIES_PROJECTION_DISPLAY2_INDEX  Index into the provided query projections.  0x00000004 
int  QUERIES_PROJECTION_QUERY_INDEX  Index into the provided query projections.  0x00000002 

Public Constructors

            SearchRecentSuggestions(Context context, String authority, int mode)
Although provider utility classes are typically static, this one must be constructed because it needs to be initialized using the same values that you provided in your SearchRecentSuggestionsProvider.

Public Methods

          void  clearHistory()
Completely delete the history.
          void  saveRecentQuery(String queryString, String line2)
Add a query to the recent queries list.

Protected Methods

          void  truncateHistory(ContentResolver cr, int maxEntries)
Reduces the length of the history table, if it's getting too big.
Methods inherited from class java.lang.Object

Details

Constants

public static final String[] QUERIES_PROJECTION_1LINE

This is the database projection that can be used to view saved queries, when configured for one-line operation.

public static final String[] QUERIES_PROJECTION_2LINE

This is the database projection that can be used to view saved queries, when configured for two-line operation.

public static final int QUERIES_PROJECTION_DATE_INDEX

Index into the provided query projections. For use with Cursor.update methods.
Constant Value: 1 (0x00000001)

public static final int QUERIES_PROJECTION_DISPLAY1_INDEX

Index into the provided query projections. For use with Cursor.update methods.
Constant Value: 3 (0x00000003)

public static final int QUERIES_PROJECTION_DISPLAY2_INDEX

Index into the provided query projections. For use with Cursor.update methods.
Constant Value: 4 (0x00000004)

public static final int QUERIES_PROJECTION_QUERY_INDEX

Index into the provided query projections. For use with Cursor.update methods.
Constant Value: 2 (0x00000002)

Public Constructors

public SearchRecentSuggestions(Context context, String authority, int mode)

Although provider utility classes are typically static, this one must be constructed because it needs to be initialized using the same values that you provided in your SearchRecentSuggestionsProvider.

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.

Public Methods

public void clearHistory()

Completely delete the history. Use this call to implement a "clear history" UI.

public void saveRecentQuery(String queryString, String line2)

Add a query to the recent queries list.

Parameters

queryString The string as typed by the user. This string will be displayed as the suggestion, and if the user clicks on the suggestion, this string will be sent to your searchable activity (as a new search query).
line2 If you have configured your recent suggestions provider with DATABASE_MODE_2LINES, you can pass a second line of text here. It will be shown in a smaller font, below the primary suggestion. When typing, matches in either line of text will be displayed in the list. If you did not configure two-line mode, or if a given suggestion does not have any additional text to display, you can pass null here.

Protected Methods

protected void truncateHistory(ContentResolver cr, int maxEntries)

Reduces the length of the history table, if it's getting too big.

Parameters

cr Convenience copy of the content resolver.
maxEntries Max entries to leave in the table. 0 means remove all entries.
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48