I have a a custom search suggestions provider. Now, this doesn't really provide suggestion per se but search shortcuts. Here's the custom provider that I've written:
public class QuickSearchProvider extends SearchRecentSuggestionsProvider {
public final static String AUTHORITY = "com.example.testapp.providers.QuickSearchProvider";
public final static int MODE = DATABASE_MODE_QUERIES | DATABASE_MODE_2LINES;
public QuickSearchProvider() {
setupSuggestions(AUTHORITY, MODE);
}
public Cursor query(Uri uri, String[] projection, String sel,
String[] selArgs, String sortOrder) {
MatrixCursor cursor = new MatrixCursor(new String[] {
BaseColumns._ID,
SearchManager.SUGGEST_COLUMN_TEXT_1,
SearchManager.SUGGEST_COLUMN_TEXT_2,
SearchManager.SUGGEST_COLUMN_ICON_1,
SearchManager.SUGGEST_COLUMN_INTENT_ACTION});
cursor.addRow(new Object[] { 0, "Plants", "Search Plants", android.R.drawable.ic_menu_search, Search.SEARCH_PLANTS_ACTION});
cursor.addRow(new Object[] { 1, "Birds", "Search Birds", android.R.drawable.ic_menu_search, Search.SEARCH_BIRDS_ACTION });
return new MergeCursor(new Cursor[] { cursor });
}
}
In my activity which contains the search field, I've written a handler inside the onNewIntent
method. Here's an example:
protected void onNewIntent(Intent intent) {
if (Search.SEARCH_PLANTS_ACTION.equals(intent.getAction())) {
...
} else if (Search.SEARCH_BIRDS_ACTION.equals(intent.getAction())) {
...
}
}
As you can see I can easily check which search shortcut was selected but I can't seem to figure out how to get the original query string. Any help?
(On a side note: if you find that my implementation of the custom search suggestion provider is wrong or could be improved, please let me know.)
Thanks.