Most visited

Recently visited

Added in API level 1

SearchRecentSuggestions

public class SearchRecentSuggestions
extends Object

java.lang.Object
   ↳ android.provider.SearchRecentSuggestions


这是一个实用程序类,提供对 SearchRecentSuggestionsProvider访问。

与某些实用程序类不同,它必须实例化并正确初始化,以便它可以配置为与您创建的搜索建议提供程序一起运行。

通常,您会在可搜索的活动中执行此操作,每次您收到传入的ACTION_SEARCH意图时。 记录每个传入查询的代码如下所示:

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

有关工作示例,请参阅samples / ApiDemos / app中的SearchSuggestionSampleProvider和SearchQueryResults。

Developer Guides

有关在应用程序中使用搜索建议的信息,请阅读 Adding Recent Query Suggestions开发人员指南。

Summary

Constants

int QUERIES_PROJECTION_DATE_INDEX

索引到提供的查询预测。

int QUERIES_PROJECTION_DISPLAY1_INDEX

索引到提供的查询预测。

int QUERIES_PROJECTION_DISPLAY2_INDEX

索引到提供的查询预测。

int QUERIES_PROJECTION_QUERY_INDEX

索引到提供的查询预测。

Fields

public static final String[] QUERIES_PROJECTION_1LINE

这是数据库投影,可用于查看保存的查询,当配置为单行操作时。

public static final String[] QUERIES_PROJECTION_2LINE

这是数据库投影,可用于查看保存的查询,当配置为双线操作时。

Public constructors

SearchRecentSuggestions(Context context, String authority, int mode)

尽管提供程序实用程序类通常是静态的,但必须构建此实用程序类,因为它需要使用您在 SearchRecentSuggestionsProvider提供的相同值进行初始化。

Public methods

void clearHistory()

完全删除历史记录。

void saveRecentQuery(String queryString, String line2)

将查询添加到最近的查询列表中。

Protected methods

void truncateHistory(ContentResolver cr, int maxEntries)

减少历史表的长度,以防止它变得太大。

Inherited methods

From class java.lang.Object

Constants

QUERIES_PROJECTION_DATE_INDEX

Added in API level 1
int QUERIES_PROJECTION_DATE_INDEX

索引到提供的查询预测。 用于Cursor.update方法。

常数值:1(0x00000001)

QUERIES_PROJECTION_DISPLAY1_INDEX

Added in API level 1
int QUERIES_PROJECTION_DISPLAY1_INDEX

索引到提供的查询预测。 用于Cursor.update方法。

常量值:3(0x00000003)

QUERIES_PROJECTION_DISPLAY2_INDEX

Added in API level 1
int QUERIES_PROJECTION_DISPLAY2_INDEX

索引到提供的查询预测。 用于Cursor.update方法。

常量值:4(0x00000004)

QUERIES_PROJECTION_QUERY_INDEX

Added in API level 1
int QUERIES_PROJECTION_QUERY_INDEX

索引到提供的查询预测。 用于Cursor.update方法。

常量值:2(0x00000002)

Fields

QUERIES_PROJECTION_1LINE

Added in API level 1
String[] QUERIES_PROJECTION_1LINE

这是数据库投影,可用于查看保存的查询,当配置为单行操作时。

QUERIES_PROJECTION_2LINE

Added in API level 1
String[] QUERIES_PROJECTION_2LINE

这是数据库投影,可用于查看保存的查询,当配置为双线操作时。

Public constructors

SearchRecentSuggestions

Added in API level 1
SearchRecentSuggestions (Context context, 
                String authority, 
                int mode)

尽管提供程序实用程序类通常是静态的,但必须构建此实用程序类,因为它需要使用您在 SearchRecentSuggestionsProvider提供的相同值进行初始化。

Parameters
context Context
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.

也可以看看:

Public methods

clearHistory

Added in API level 1
void clearHistory ()

完全删除历史记录。 使用此调用来实现“清除历史记录”UI。 任何基于先前操作实现搜索建议的应用程序(例如最近的查询,浏览的页面/项目等)都应该为用户提供清除历史记录的方法。 如果用户不希望他们最近的搜索被设备的其他用户重播(通过建议),则这给用户提供了一种隐私措施。

saveRecentQuery

Added in API level 1
void saveRecentQuery (String queryString, 
                String line2)

将查询添加到最近的查询列表中。 立即返回,在后台执行保存。

Parameters
queryString String: 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 String: 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

truncateHistory

Added in API level 1
void truncateHistory (ContentResolver cr, 
                int maxEntries)

减少历史表的长度,以防止它变得太大。

Parameters
cr ContentResolver: Convenience copy of the content resolver.
maxEntries int: Max entries to leave in the table. 0 means remove all entries.

Hooray!