Adding the search capability to applications using the following as instructions.
developer.android.com/reference/android/app/SearchManager.html
The following was done to allow searching
Added a button that when clicked calls "onSearchRequested"
Also added "setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);"
so that handsets with keyboards can just start typing to search
Added a search result activity with the following code
(doSearchQuery not included to avoid verbosity)
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle);
final Intent queryIntent = getIntent();
final String queryAction = queryIntent.getAction();
if (Intent.ACTION_SEARCH.equals(queryAction)) { doSearchWithIntent(queryIntent);
} }
private void doSearchWithIntent(final Intent queryIntent) {
final String queryString = queryIntent.getStringExtra(SearchManager.QUERY);
doSearchWithQuery(queryString); }
Add a searchable.xml file in the xml folder (This controls aspects of the search + UI)
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/search_label"
android:hint="@string/search_hint"
android:searchMode="showSearchIconAsBadge"
android:searchButtonText="@string/search" android:inputType="text">
</searchable>
Add "Glue" xml to point the entire application to the search activity
<meta-data android:name="android.app.default_searchable" android:value=".search.SearchResults" />
The define the search activity in the manifest include the search intent and link to the searchable xml file
<activity android:name=".search.SearchResults"
android:launchMode="singleTop"
android:label="Search">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable" />
</activity>