从ContentProvider的访问appSearchData包ContentProvider、appSearchData

2023-09-06 22:03:43 作者:只是属于自己的冷漠

一个活动被认为是能够提供上下文信息到这样一个内容提供商

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;
}

从提供商的搜索建议和结果应仅限于'分类',但我找不到在哪里从我的ContentProvider访问appSearchData包。

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.

推荐答案

使用此为onSearchRequested:

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);