1. Title:
How can applications fully support search?
2. Introduction:
If you want an application to support global search, you must configure a series of configurations for the application and enable the content provider that can be accessed by the outside world to provide search results to the search application (quicksearchbox, based on the configuration information, the application can be identified as a search source by the Search framework, and the search application (quicksearchbox) can also obtain the search result by parsing the configuration information group and assembling it into the contentprovider Of The URI request application.
3. Configuration implementation:
1. An activity should exist in the application. The basic configuration of this activity in androidmanifest. XML is as follows:
<Activity Android: Name = "com. Focus. fishmeactivity" Android: Label = "@ string/app_name">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
<! -- Start of global search -->
<! -- The intent-filter is the action configured in the intent when the search framework starts this activity. For details, refer to the second item of the activity below -->
<Intent-filter>
<Action Android: Name = "com. Focus. fish_me"/>
<Category Android: Name = "android. Intent. Category. Default"/>
</Intent-filter>
<! -- The intent-filter is fixed and does not need to be changed. It can be copied and used directly. -->
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Search"/>
<Category Android: Name = "android. Intent. Category. Default"/>
</Intent-filter>
<! -- This meta-data is also a fixed configuration that does not need to be modified. It requires an XML file. The following shows the most standard and simplest configuration of this XML file. Please continue to look down.
(Searchable. XML) -->
<Meta-data Android: Name = "android. App. searchable" Android: Resource = "@ XML/searchable"/>
<! -- Global Search supports end -->
</Activity>
Let's talk about the role of this activity:
First, such an activity must exist in your application, because after you configure the Code marked with red annotations above, this activity can be recognized as a search source,
Your application supports global search.
Second, when the result information is searched and a result item is clicked, the activity is displayed.
2. searchable. XML is the most basic and simple configuration:
<? XML version = "1.0" encoding = "UTF-8"?>
<Searchable xmlns: Android = "http://schemas.android.com/apk/res/android"
<! -- These two attributes must be fixed. -->
Android: Label = "@ string/search_label"
Android: includeinglobalsearch = "true"
<! -- This authority is the authority of the contentprovider you wrote. -->
Android: searchsuggestauthority = "com. Focus. fish_me_authority"
<! -- This action is the action you configured in the preceding 1 -->
Android: searchsuggestintentaction = "com. Focus. fish_me">
</Searchable>
The attributes of this document will be introduced in a later article.
3. Configure contentprovider in the androidmanifest. xml file:
<Provider
Android: Name = "fishmeprovider"
<! -- This authority corresponds to the Authority configured in preceding 2 -->
Android: Authorities = "com. Focus. fish_me_authority"
/>
4. How to build content provider:
In quicksearchbox, you can use contentresolver to call the query (Uri, string [], String, string [], string) method of the content provider for information search. The application must implement
This method returns the searched cursor object.
The following describes the parameters of the contentprovider query method:
The first parameter (URI ):
Content: // authority/suggestion. Path/search_suggest_query/querystr? Limit = 50
Authority: corresponds to the Android: searchsuggestauthority attribute in the searchable. xml file.
Suggestion. Path: corresponds to the Android: searchsuggestpath attribute in the searchable. xml file.
Search_suggest_query: a fixed string.
Querystr: query string.
Limit: number of queries.
The second parameter (projection) is always null.
The third parameter (selection) corresponds to the Android: searchsuggestselection attribute in the searchable. xml file. The query method of contentprovider calls SQLite data.
The query method of the database. This parameter is used to form the condition after where in the SQL statement, for example, where name like ?," Name like? "Is the value of the selection parameter. Note that,
Android: the query conditions configured in the searchsuggestselection attribute cannot be connected with symbols such as "and" or "(cannot be written as" name like? And age like ?").
The fourth parameter (selectionargs): If the Android: searchsuggestselection attribute value in the searchable. xml file is not empty, the program uses the query string as the array.
The first element is also a unique element. The query condition is defined in the third parameter above. This parameter is used to assign a value to the question mark in the query condition.
Fifth parameter: Always null.
This method returns the searched data in the form of a cursor object.