怎么在Android Quick Search Box中添加自己的app,按照小弟我的意愿去Search(转载)

如何在Android Quick Search Box中添加自己的app,按照我的意愿去Search(转载)

       在Search settings里,Searchable items中原本有5个可勾选的项,分别是:Web , Apps , Contacts , Messaging , Music 。显然这满足不了我们所有的需求,用户的欲望无止境嘛 >_< || ~~~ 下面就介绍怎样添加我们的自己app潜伏在 Quick Search Box中,成为一个Searchable items 。

        本地搜索不可不提的是ContentProvider和ContentResolver 。我们的App通过ContentProvider将自己的数据公开,允许别人家的app来获取自己的数据信息。与此同时,通过ContentResolver 获取对应的ContentProvider的远程访问方法。ContentProvider和ContentResolver通过Binder机制连接。

        Android中有一个SearchManager模块,是专门用于处理搜索请求的。每个App启动搜索功能时,都要通过它来完成。

        按照自己的意愿的写好一个app,也可以采用第三方app,想试一试的朋友可以直接采用development/samples/SearchDictionary为例子,参考学习。

        在我们自己的app的AndroidManifest.xml中,需要对intent 和 res/xml/searchable.xml 进行注册。

  

view plaincopy to clipboardprint?
  1. <intent-filter>  
  2.     <action android:name="android.intent.action.SEARCH" />  
  3.     <category android:name="android.intent.category.DEFAULT" />  
  4. </intent-filter>  
  5.               
  6. <meta-data android:name="android.app.searchable"  
  7.        android:resource="@xml/searchable" />  

 

     还需要公开自己的数据,供Quick Search Box 使用

 

view plaincopy to clipboardprint?
  1. <!-- Provides search suggestions for words and their definitions. -->  
  2. <provider android:name="DictionaryProvider"  
  3.        android:authorities="dictionary"  
  4.        android:syncable="false" />  

 

     在res/xml/searchable.xml中,要注意searchSuggestAuthority和AndroidManifest.xml中的要对应上,

       把app导入QSB的关键句是下面两句

android:searchSettingsDescription="@string/settings_description"

android:includeInGlobalSearch="true" 

 

view plaincopy to clipboardprint?
  1. <searchable xmlns:android="http://schemas.android.com/apk/res/android"  
  2.        android:label="@string/search_label"  
  3.        android:searchSettingsDescription="@string/settings_description"  
  4.        android:includeInGlobalSearch="true"  
  5.        android:searchSuggestAuthority="dictionary"  
  6.        android:searchSuggestIntentAction="android.intent.action.VIEW">  
  7. </searchable>  

 

   编译生成apk推入,先在Search setting中手动勾选上自己的应用选项,就可以了。


   在package/apps/QuickSearchBox/tests/下,还有三个有意思的app,可以直接添加到QuickSearchBox中。

    To run the tests use the command:
    "adb shell am instrument -w com.android.quicksearchbox.tests/android.test.InstrumentationTestRunner"



   丰富一下QSB吧~

转载:http://blog.csdn.net/yiyaaixuexi/archive/2011/03/02/6218823.aspx