How Android associates searchmanager with user dictionary

Source: Internet
Author: User

HowSearchmanagerAssociated with user dictionary?

First, let's take a look at the search

 

1) In your<Activity>, An intent filter, and a reference toSearchable. xmlFile (described below ):

 
<Intent-filter>
    <Action     Android: Name =  "Android. Intent. Action. Search"     />  
<Category Android: Name = "Android. Intent. Category. Default" />
</Intintent-filter>

<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 bySearch suggestionsSection of the searchmanager docs:

 
 
 <! -- Provides search suggestions for words and their definitions. -->  
<Provider Android: Name = "Dictionaryprovider"
Android: Authorities = "Dictionary"
Android: syncable = "False" />

InSearchable. xmlFile, 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 ofSearchable. xmlOf 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 thatAndroid: searchsuggestauthorityAttribute refers to the authority of the content provider we declared inAndroidmanifest. xml.

 
 

 
To makeSearchCan containDictionary, We need to do:

 
 
    • Implement a search interface using Android's search framework
    • Provide Custom Search suggestions and offer them in quick search box
    • Create an SQLite database and an fts3 table for full-text searches
    • CreateContent ProviderTo perform all search and suggestion queries
    • UseSimplecursoradapterTo bind data from a cursor to a listview.


Note:For the original version of searchable dictionary,

Which reads words from a file instead of a database and uses a customBaseadapter,

See the SDK samples encoded with the platforms for API Level 4-6.

 

In fact, the search framework does not provide APIs for searching data added by users. To achieve our goal,

You must use APIs that support our data. What should I do? For example, if the data has SQLite database,

You should use Android. database. SQLite APIs to complete searches.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.