http://blog.csdn.net/mayingcai1987/article/details/6268732
1. Title:
How the application fully supports search
2. Introduction:
If you want an application to support global search, you must make a series of configurations for the application, and enable content providers that can be accessed by the outside world to provide search results to the search application (Quicksearchbox), which, depending on the configuration information, can be identified by the search framework as a search source. The Search application (Quicksearchbox) can also obtain search results by parsing the configuration information group into the URI request app's ContentProvider.
3. Configuration implementation:
1. There should be an activity in the application, the basic configuration of the activity in Androidmanifest.xml, 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>
<!--global Search support start-up
<!--This intent-filter is the search framework to start the activity when the action configured in intent is shown below activity action second--
<intent-filter>
<action android:name= "Com.focus.FISH_ME"/>
<category android:name= "Android.intent.category.DEFAULT"/>
</intent-filter>
<!--This intent-filter is a fixed configuration that does not need to be changed and copied directly to the past
<intent-filter>
<action android:name= "Android.intent.action.SEARCH"/>
<category android:name= "Android.intent.category.DEFAULT"/>
</intent-filter>
<!--This meta-data is also fixed configuration does not need to change, he needs an XML file, below will have 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 support End--
</activity>
Let's talk about the role of this activity:
First, such an activity must exist in your application, since you have configured the code above that I annotated with a red annotation, the activity can be identified as the source of the search,
Your app supports global search.
Second, when you click on an outcome item after searching for a result, the activity will be opened to show what is being searched for.
2. Searchable.xml the most basic, simplest configuration:
<?xml version= "1.0" encoding= "Utf-8"?>
<searchable xmlns:android= "Http://schemas.android.com/apk/res/android"
<!--These two properties are fixed must have--
Android:label= "@string/search_label"
Android:includeinglobalsearch= "true"
<!--This authority is your contentprovider authority, and here's what it says--
Android:searchsuggestauthority= "Com.focus.FISH_ME_AUTHORITY"
<!--This action is the action--> you configured in 1 above
android:searchsuggestintentaction= "Com.focus.FISH_ME" >
</searchable>
The properties of this file are described in a later article.
3. Configure the ContentProvider in the Androidmanifest.xml file:
<provider
Android:name = "Fishmeprovider"
<!--This authority corresponds to the authority configured in the above 2
Android:authorities= "Com.focus.FISH_ME_AUTHORITY"
/>
4. How to build content Provider:
In Quicksearchbox, the query (Uri, string[], String, string[], String) method of the content provider is called by Contentresolver to search for information, and the application must actually
This method is now returned and returns the cursor object that was searched for.
The parameters of the query method for ContentProvider are described below:
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: Fixed string.
QUERYSTR: query string.
Limit: Number of query bars.
The second parameter (projection): Always null.
Third parameter (selection): corresponding to the Android:searchsuggestselection attribute in the Searchable.xml file, the ContentProvider query method will call the SQLite data
The library's query method, which uses this parameter to form the condition in the SQL statement, such as: where Name like? "Is the value of the selection parameter, note that
The query condition configured in the Android:searchsuggestselection property cannot concatenate multiple conditions with symbols such as "and" or "or" (cannot be written as: "Name like?"). And age like? " )。
Fourth parameter (Selectionargs): If the Android:searchsuggestselection property value in the Searchable.xml file is not NULL, the program will make the query string the array
The first element, which is also the only element, defines the query condition in the third argument above, which is the function of assigning a question mark to a query in a condition.
The fifth parameter: always null.
The method returns the data that is being searched as a cursor object.
Global Search in Android (Quicksearchbox) detailed