Home | History | Annotate | Download | only in articles
      1 page.title=Quick Search Box
      2 @jd:body
      3 
      4 
      5 <div id="qv-wrapper">
      6 <div id="qv">
      7 
      8   <h2>See also</h2>
      9   <ol>
     10     <li><a href="{@docRoot}guide/topics/search/index.html">Search</a></li>
     11     <li><a href="{@docRoot}resources/samples/SearchableDictionary/index.html">Searchable Dictionary
     12 sample</a></li>
     13   </ol>
     14 
     15 </div>
     16 </div>
     17 
     18 <div class="figure" style="width:233px">
     19 <img src="images/qsb_002.png" alt="" height="350" />
     20 </div>
     21 
     22 <p>Starting with Android 1.6, the platform includes support for Quick Search
     23 Box (QSB), a powerful, system-wide search framework. Quick Search Box makes it
     24 possible for users to quickly and easily find what they're looking for, both on
     25 their devices and on the web. It suggests content on your device as you type,
     26 like apps, contacts, browser history, and music. It also offers results from the
     27 web search suggestions, local business listings, and other info from
     28 Google, such as stock quotes, weather, and flight status. All of this is
     29 available right from the home screen, by tapping on Quick Search Box.</p>
     30 
     31 <p>What
     32 we're most excited about with this new feature is the ability for you,
     33 the developers, to leverage the QSB framework to provide quicker and
     34 easier access to the content inside your apps. Your apps can provide
     35 search suggestions that will surface to users in QSB alongside other
     36 search results and suggestions. This makes it possible for users to
     37 access your application's content from outside your applicationfor
     38 example, from the home screen.</p>
     39 
     40 <p class="note"><strong>Note:</strong> The code fragments in this document are
     41 related to a sample app called <a
     42 href="{@docRoot}resources/samples/SearchableDictionary/index.html"
     43 title="Searchable Dictionary">Searchable Dictionary</a>. The app is
     44 available for Android 1.6 and later platforms.</p>
     45 
     46 <h3>The story before now: searching within your app</h3>
     47 
     48 <p>Platform releases versions previous to Android 1.6 already provided a mechanism
     49 that let you expose search and search suggestions in your app, as described in
     50 the docs for {@link android.app.SearchManager}. That mechanism has not changed
     51 and requires the following two things in your
     52 <code>AndroidManifest.xml</code>:</p>
     53 
     54 <p>1) In your <code>&lt;activity&gt;</code>, an intent filter, and a reference 
     55 to a <code>searchable.xml</code> file (described below):</p>
     56 
     57 <pre class="prettyprint">&lt;intent-filter&gt;
     58     &lt;action android:name="android.intent.action.SEARCH" /&gt;
     59     &lt;category android:name="android.intent.category.DEFAULT" /&gt;
     60 &lt;/intent-filter&gt;
     61             
     62 &lt;meta-data android:name="android.app.searchable"
     63        android:resource="@xml/searchable" /&gt;</pre>
     64 
     65 <p>2) A content provider that can provide search suggestions according to the
     66 URIs and column formats specified by the 
     67 <a href="{@docRoot}reference/android/app/SearchManager.html#Suggestions">Search Suggestions</a>
     68 section of the SearchManager docs:</p>
     69 
     70 <pre class="prettyprint">&lt;!-- Provides search suggestions for words and their definitions. --&gt;
     71 &lt;provider android:name="DictionaryProvider"
     72        android:authorities="dictionary"
     73        android:syncable="false" /&gt;</pre>
     74 
     75 <p>In the <code>searchable.xml</code> file, you specify a few things about how
     76 you want the search system to present search for your app, including the
     77 authority of the content provider that provides suggestions for the user as they
     78 type. Here's an example of the <code>searchable.xml</code> of an Android app
     79 that provides search suggestions within its own activities:</p>
     80 
     81 <pre class="prettyprint">&lt;searchable xmlns:android="http://schemas.android.com/apk/res/android"
     82         android:label="@string/search_label"
     83         android:searchSuggestAuthority="dictionary"
     84         android:searchSuggestIntentAction="android.intent.action.VIEW"&gt;
     85 &lt;/searchable&gt;</pre>
     86 
     87 <p>Note that the <code>android:searchSuggestAuthority</code> attribute refers to
     88 the authority of the content provider we declared in
     89 <code>AndroidManifest.xml</code>.</p>
     90 
     91 <p>For more details on this, see the 
     92 <a href="{@docRoot}reference/android/app/SearchManager.html#SearchabilityMetadata">Searchability Metadata 
     93 section</a> of the of the SearchManager docs.</p>
     94 
     95 <h3>Including your app in Quick Search Box</h3>
     96 
     97 <div class="sidebox-wrapper">
     98 <div class="sidebox">
     99 <h2>Searchable Dictionary Sample App</h2>
    100 <p>Quick Search Box provides a really cool way to make it easier and faster for
    101 users to access your app's content. To help you get your app started with it,
    102 we've created a sample app that simply provides access to a small dictionary of
    103 words in QSB. The app is called Searchable Dictionary, and we encourage you to
    104 <a href="{@docRoot}resources/samples/SearchableDictionary/index.html">check it
    105 out</a>.</p>
    106 </div>
    107 </div>
    108 
    109 <p>In Android 1.6, we added a new attribute to the metadata for searchables:
    110 <code>android:includeInGlobalSearch</code>. By specifying this as
    111 <code>"true"</code> in your <code>searchable.xml</code>, you allow QSB to pick
    112 up your search suggestion content provider and include its suggestions along
    113 with the rest (if the user enables your suggestions from the system search
    114 settings).</p>
    115 
    116 <p>You should also specify a string value for 
    117 <code>android:searchSettingsDescription</code>, which describes to users what
    118 sorts of suggestions your app provides in the system settings for search.</p>
    119 
    120 <pre class="prettyprint">&lt;searchable xmlns:android="http://schemas.android.com/apk/res/android"
    121        android:label="@string/search_label"
    122        <span style="background: rgb(255, 255, 0) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">android:searchSettingsDescription="@string/settings_description"</span>
    123        <span style="background: rgb(255, 255, 0) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">android:includeInGlobalSearch="true"</span>
    124        android:searchSuggestAuthority="dictionary"
    125        android:searchSuggestIntentAction="android.intent.action.VIEW"&gt;
    126 &lt;/searchable&gt;</pre>
    127 
    128 <p>These new attributes are supported only in Android 1.6 and later.</p>
    129 
    130 <h3>What to expect</h3>
    131 
    132 <p>The
    133 first and most important thing to note is that when a user installs an
    134 app with a suggestion provider that participates in QSB, this new app
    135 will <em>not</em> be enabled for QSB by default. The user can choose
    136 to enable particular suggestion sources from the system settings for
    137 search (by going to "Search" &gt; "Searchable items" in settings).</p>
    138 
    139 <p>You
    140 should consider how to handle this in your app. Perhaps show a notice
    141 that instructs the user to visit system settings and enable your app's
    142 suggestions.</p>
    143 
    144 <p>Once the user enables your searchable item, the
    145 app's suggestions will have a chance to show up in QSB, most likely
    146 under the "more results" section to begin with. As your app's
    147 suggestions are chosen more frequently, they can move up in the list.</p>
    148 
    149 <img src="images/qsb.png" style="width: 233px; height: 349.5px;">  
    150 <img id="k0vw" src="images/qsb_003.png" style="width: 233px; height: 349.5px;">
    151 
    152 <h3>Shortcuts</h3>
    153 
    154 <p>One
    155 of our objectives with QSB is to make it faster for users to access the
    156 things they access most often. One way we've done this is by
    157 'shortcutting' some of the previously chosen search suggestions, so
    158 they will be shown immediately as the user starts typing, instead of
    159 waiting to query the content providers. Suggestions from your app may
    160 be chosen as shortcuts when the user clicks on them.</p>
    161 
    162 <p>For dynamic suggestions that may wish to change their content (or become invalid)
    163 in the future, you can provide a 'shortcut id'. This tells QSB to query
    164 your suggestion provider for up-to-date content for a suggestion after
    165 it has been displayed. For more details on how to manage shortcuts, see
    166 the Shortcuts section 
    167 <a href="{@docRoot}reference/android/app/SearchManager.html#ExposingSearchSuggestionsToQuickSearchBox">within the SearchManager docs</a>.</p>
    168