TrippinBilly TrippinBilly - 1 year ago 57
Android Question

How to send selected search suggestion data to a custom activity

I've been able to successfully implement a search widget experience to use a content provider that returns a cursor with row data. The custom search suggestions appear nicely in a list under the ActionBar search box as expected.

What I need to do is send the selected search suggestion to a custom activity (presumably in a bundle?) It seems so simple but I've not been able to figure it out.

Currently, this code will ask me what app I'd like to use to open the intent. I'd like to send the selected suggestion data to the "MainActivity" in the manifest listed further below.

Thanks in advance!


<?xml version="1.0" encoding="utf-8"?>

<searchable xmlns:android=""
android:searchMode="queryRewriteFromText" >


the search activity

public void onCreate(Bundle savedInstanceState) {

Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
// Handle the normal search query case
android.util.Log.w("****", "in ACTION_SEARCH");
String query = intent.getStringExtra(SearchManager.QUERY);
} else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
// Handle a suggestions click (because the suggestions all use ACTION_VIEW)
android.util.Log.w("****", "in ACTION_VIEW");

private void doSearch(String query) {

android.util.Log.w("search query:", query);


private void doView(final Intent queryIntent) {
Uri uri = queryIntent.getData();
String action = queryIntent.getAction();
Intent i = new Intent(action);

the search section of the manifest:

android:label="@string/app_name" >
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

<activity android:name="com.myapp.SearchableActivity" >
<action android:name="android.intent.action.SEARCH" />
<meta-data android:name=""

<provider android:authorities="com.myapp.SearchProvider"
android:name="com.myapp.SearchProvider" />

<meta-data android:name=""
android:value="com.myapp.SearchableActivity" />

Answer Source

Phew, I figured it out.

In my content provider, I have to add a column in the Matrix cursor called: SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA and put in the value of the suggestion.

In my search activity doView() method I can extract it with:

Bundle extras = queryIntent.getExtras();
String data = extras.getString(SearchManager.EXTRA_DATA_KEY);
android.util.Log.w("keySet =", extras.keySet().toString()); // this showed me the keys available
android.util.Log.w(SearchManager.EXTRA_DATA_KEY, data);

From here, I can pass that on to my custom activity/intent. There may be a better way, but this works!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download