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

來源:互聯網
上載者:User

       在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 進行註冊。

   <intent-filter><br /> <action android:name="android.intent.action.SEARCH" /><br /> <category android:name="android.intent.category.DEFAULT" /><br /></intent-filter></p><p><meta-data android:name="android.app.searchable"<br /> android:resource="@xml/searchable" />

 

     還需要公開自己的資料,供Quick Search Box 使用

<!-- Provides search suggestions for words and their definitions. --><br /><provider android:name="DictionaryProvider"<br /> android:authorities="dictionary"<br /> android:syncable="false" />

 

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

       把app匯入QSB的關鍵句是下面兩句
android:searchSettingsDescription="@string/settings_description"
android:includeInGlobalSearch="true"

<searchable xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:label="@string/search_label"<br /> android:searchSettingsDescription="@string/settings_description"<br /> android:includeInGlobalSearch="true"<br /> android:searchSuggestAuthority="dictionary"<br /> android:searchSuggestIntentAction="android.intent.action.VIEW"><br /></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吧~

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.