Introducing Quick Search Box for Android
2009-11-02 16:54
351 查看
Introducing
Quick Search Box for Android
由于android
的官方博客中国地区的
IP
都打不开,所以这篇文章可能很多开发者都想看而看不到的,这里转载一下。并加上自己的中文理解。One of the new
features we're really proud of in the Android 1.6 release is Quick Search Box
for Android. This is our new system-wide search framework, which makes it
possible for users to quickly and easily find what they're looking for, both on
their devices and on the web. It suggests content on your device as you type,
like apps, contacts, browser history, and music. It also offers results from
the web search suggestions, local business listings, and other info from
Google, such as stock quotes, weather, and flight status. All of this is
available right from the home screen, by tapping on Quick Search Box (QSB).What we're most excited about with this new
feature is the ability for you, the developers, to leverage the QSB framework
to provide quicker and easier access to the content inside your apps. Your apps
can provide search suggestions that will surface to users in QSB alongside
other search results and suggestions. This makes it possible for users to
access your application's content from outside your application—for example,
from the home screen.The code fragments below are related to a
new demo app for Android 1.6 called Searchable Dictionary
.下面的代码都是基于
android1.6
新添加的一个例子代码
SearchableDictionary
。
The story before now: searching within your app
In previous releases, we already provided amechanism for you to expose search and search suggestions in your app as
described in the docs for SearchManager
. This mechanism has not changed and
requires the following two things in your
AndroidManifest.xml
:在前面的版本中,我们已经引入了一个
SearchManager
的机制,这种机制在
1.6
中并没有改变,需要我们在
AndroidManifest
中加入下面两个东西。1、In your
<activity>
, an intent filter, and a reference to a
searchable.xml
file (described below):
,在你的
<Activity>
中加入:
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
2、A content provider that can
provide search suggestions according to the URIs and column formats specified
by the Search
Suggestions section
of the SearchManager docs:
<!-- Provides search suggestions for words and their definitions. -->
<provider android:name="DictionaryProvider"
android:authorities="dictionary"
android:syncable="false" />In the
searchable.xml
file,
you specify a few things about how you want the search system to present search
for your app, including the authority of the content provider that provides
suggestions for the user as they type. Here's an example of the
searchable.xml
of an Android app that provides search suggestions within its own
activities:
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/search_label"
android:searchSuggestAuthority="dictionary"
android:searchSuggestIntentAction="android.intent.action.VIEW">
</searchable>
Note that the
android:searchSuggestAuthority
attribute refers to the authority of the content provider we declared in
AndroidManifest.xml
.For more details on this, see the Searchability
Metadata section
of the SearchManager docs.
Including your app in Quick Search Box
In Android 1.6, we added a new attribute to the metadatafor searchables:
android:includeInGlobalSearch
. By specifying this
as
"true"
in your
searchable.xml
, you allow
QSB to pick up your search suggestion content provider and include its
suggestions along with the rest (if the user enables your suggestions from the
system search settings).You should also specify a string value for
android:searchSettingsDescription
,
which describes to users what sorts of suggestions your app provides in the
system settings for search.
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/search_label"
android:searchSettingsDescription="@string/settings_description"
android:includeInGlobalSearch="true"
android:searchSuggestAuthority="dictionary"
android:searchSuggestIntentAction="android.intent.action.VIEW">
</searchable>
These new attributes are supported only in Android 1.6 and
later.
What to expect
The first and most important thing to note is that when auser installs an app with a suggestion provider that participates in QSB, this
new app will notbe enabled for QSB by default. The user can choose to enable particular
suggestion sources from the system settings for search (by going to
"Search" > "Searchable items" in settings).You should consider how to handle this in your app. Perhaps
show a notice that instructs the user to visit system settings and enable your
app's suggestions.Once the user enables your searchable item, the app's
suggestions will have a chance to show up in QSB, most likely under the
"more results" section to begin with. As your app's suggestions are
chosen more frequently, they can move up in the list.
Shortcuts
One of our objectives with QSB is to make it faster forusers to access the things they access most often. One way we've done this is
by 'shortcutting' some of the previously chosen search suggestions, so they
will be shown immediately as the user starts typing, instead of waiting to
query the content providers. Suggestions from your app may be chosen as
shortcuts when the user clicks on them.For dynamic suggestions that may wish to change their
content (or become invalid) in the future, you can provide a 'shortcut id'.
This tells QSB to query your suggestion provider for up-to-date content for a
suggestion after it has been displayed. For more details on how to manage
shortcuts, see the Shortcuts section within the SearchManager docs
.
相关文章推荐
- 如何在Android Quick Search Box中添加自己的app,按照我的意愿去Search。
- android QuickSearchBox 流程浅析
- 如何在Android Quick Search Box中添加自己的app,按照我的意愿去Search。
- (OK) Building Ice Cream Sandwich (Android v4) for VirtualBox on EC2
- Android 2.3 GingerBread for VirtualBox x86编译指南
- QuickSearchBox的一点改进
- Voice Search/Actions for Android
- Android 2.3 GingerBread for VirtualBox x86编译指南
- Android 7.1.1 Launcher3 去除Quick Search Bar
- Eclipse 代码查找插件 Quick Search for Eclipse
- Building Ice Cream Sandwich (Android v4) for VirtualBox on EC2
- Foxit Mobile PDF SDK for Android_添加Text Search功能(3)
- InstaSearch - Eclipse plug-in for quick code search
- K860i的109升级需要的PinyinIME.apk和QuickSearchBox.apk两个文件
- Introducing Visual Studio’s Emulator for Android
- [leetcode] Search for a Range
- 【metasearch学习笔记】Models for metasearch_SIGIR2001
- ShareSDK for Android 2.3.9已经发布
- LeetCode 34.Search for a Range & 36.Valid Sudoku
- Android 快捷方式的创建与查询 快捷方式问题大全 获取快捷方式在Launcher数据库中的信息 Failed to find provider info for com.android.la