android - Adding Custom Suggestions

来源:互联网 发布:mill9.1编程文字教程 编辑:程序博客网 时间:2024/04/30 08:20

The default behavior is for system to pass this URI and append it with the query text. For example:

content://your.authority/optional.suggest.path/SUGGEST_URI_PATH_QUERY/puppies
Instead of using the URI, you might decide it makes more sense for your query() method to receive everything it needs to perform the look-up and you want the selection and selectionArgs parameters to carry the appropriate values.

Declaring an Intent for Suggestions


When the user selects a suggestion from the list that appears below the search dialog or widget, the system sends a custom Intent to your searchable activity. You must define the action and data for the intent.

>Note: If you do not include the android:searchSuggestIntentAction attribute in your searchable configuration, then you must include a value in the SUGGEST_COLUMN_INTENT_ACTION column for every suggestion, or the intent will fail.

>You can define the data included with the intent in two ways:

  1. Define the data for each suggestion inside the SUGGEST_COLUMN_INTENT_DATA column of your suggestions table.

b.Fragment a data URI into two pieces: the portion common to all suggestions and the portion unique to each suggestion. Place these parts into the android:searchSuggestintentData attribute of the searchable configuration and the SUGGEST_COLUMN_INTENT_DATA_ID column of your suggestions table, respectively.

Declare the piece of the URI that is common to all suggestions in the android:searchSuggestIntentDataattribute of your searchable configuration.

<?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.MyCustomSuggestionProvider"    android:searchSuggestIntentAction="android.intent.action.VIEW"    android:searchSuggestIntentData="content://com.example/datatable" 
android:searchSettingsDescription="@string/search_description" >
</searchable>
> Here's an example of how you can handle the intents during your activity onCreate() callback:
Intent intent = getIntent();if (Intent.ACTION_SEARCH.equals(intent.getAction())) {    // Handle the normal search query case    String query = intent.getStringExtra(SearchManager.QUERY);    doSearch(query);} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {    // Handle a suggestions click (because the suggestions all use ACTION_VIEW)    Uri data = intent.getData();    showResult(data);}

Note: You do not need to add an intent filter to your Android manifest file for the intent action you defined with the android:searchSuggestIntentAction attribute or SUGGEST_COLUMN_INTENT_ACTION column. The system opens your searchable activity by name to deliver the suggestion's intent, so the activity does not need to declare the accepted action.

You can rewrite the query text in the following ways:

  1. Add the android:searchMode attribute to your searchable configuration with the "queryRewriteFromText" value. In this case, the content from the suggestion's SUGGEST_COLUMN_TEXT_1 column is used to rewrite the query text.
  2. Add the android:searchMode attribute to your searchable configuration with the "queryRewriteFromData" value. In this case, the content from the suggestion's SUGGEST_COLUMN_INTENT_DATA column is used to rewrite the query text. This should only be used with URI's or other data formats that are intended to be user-visible, such as HTTP URLs. Internal URI schemes should not be used to rewrite the query in this way.
  3. Provide a unique query text string in the SUGGEST_COLUMN_QUERY column of your suggestions table. If this column is present and contains a value for the current suggestion, it is used to rewrite the query text (and override either of the previous implementations).

>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 <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="com.example.MyCustomSuggestionProvider"          android:readPermission="com.example.provider.READ_MY_DATA"          android:writePermission="com.example.provider.WRITE_MY_DATA">  <path-permission android:pathPrefix="/search_suggest_query"                   android:readPermission="android.permission.GLOBAL_SEARCH" /></provider>

>Suggestions that the user selects from Quick Search Box can be automatically made into shortcuts. These are suggestions that the system has copied from your content provider so it can quickly access the suggestion without the need to re-query your content provider.

>Using this column, you can configure the shortcut behavior for each suggestion in one of the following ways:

a.Have Quick Search Box re-query your content provider for a fresh version of the suggestion shortcut.

b.Prevent the suggestion from being copied into a shortcut at all.

c.Allow the default shortcut behavior to apply.

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.

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.

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.

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 中医药职工大学 北中医药大学 二本中医药大学 中医药大学王玉英 中医药管理部门 中医药发展论坛 中医药大学电话 省中医药研究院 中医中医药 中医中医药网 广州中医药大学第一附属医院 河南中医药大学第一附属医院 河南中医药大学附属医院 成都中医药大学附属医院 云南中医药大学教务管理系统 湖北中医药大学教务 中医药大学附属医院 湖北中医药大学教务在线 天津中医药大学第一附属医院 天津中医药大学研究生院 云南中医药大学教务系统 北京中医药大学东方学院 山东中医药大学附属医院 辽宁中医药大学附属医院 上海中医药大学研究生院 广西中医药大学第一附属医院 山东中医药大学研究生处 江西中医药大学科技学院 广州中医药大学研究生院 陕西中医药大学数字校园 湖南中医药大学附属医院 安徽中医药大学第一附属医院 山东中医药大学第二附属医院 中医药大学东方学院 陕西中医药大学附属医院 安徽中医药大学附属医院 湖南中医药大学第一附属医院 浙江中医药大学教务处 甘肃中医药大学教务网 河南中医药大学中文网 世界中医药学会联合会