问题
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.
回答1:
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);
来源:https://stackoverflow.com/questions/4397349/accessing-appsearchdata-bundle-from-contentprovider