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

转载:http://blog.csdn.net/yiyaaixuexi/article/details/6218823

        在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 进行注册。

  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 使用

  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" 

  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吧~

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值