1

An activity is supposed to be able to provide context information to a content provider like this:

@Override
public boolean onSearchRequested() {
    Bundle appSearchData = new Bundle();
    appSearchData.putByte("category", category);
    startSearch(null, false, appSearchData, false);
    return true;
}

Search suggestions and results from the provider should be limited to 'category', but I can't find where to access the appSearchData bundle from my ContentProvider.

  • possible duplicate of [Pass a parameter to a Custom Search Suggestion ContentProvider](http://stackoverflow.com/questions/7947016/pass-a-parameter-to-a-custom-search-suggestion-contentprovider) – aleb Dec 03 '13 at 13:05

1 Answers1

0

Use this for onSearchRequested:

@Override
public boolean onSearchRequested() {
    SearchManager searchManager = (SearchManager)getSystemService(Context.SEARCH_SERVICE);

    if(searchManager!=null)
    {
        // start the search with the appropriate searchable activity
        // so we get the correct search hint in the search dialog
            Bundle b = new Bundle();
            b.putString("context", indicator);
            searchManager.startSearch(null, false,new ComponentName(this, YourClass.class), b, false);
    return true;
}
return false;
}

And this is your searchable class:

Bundle b = intent.getBundleExtra(SearchManager.APP_DATA);
Joris
  • 1,437
  • 1
  • 15
  • 22
  • @bitbox Sorry for late response, you get it by simply calling the "getIntent()" method: Intent intent = getIntent() in the onCreate – Joris Mar 04 '11 at 13:29
  • 3
    The question is about the content provider which returns search suggestion, not about the search activity. – aleb Dec 03 '13 at 13:04