Accessing appSearchData bundle from ContentProvider

孤街醉人 提交于 2019-12-23 03:27:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!