【问题标题】:Accessing appSearchData bundle from ContentProvider从 ContentProvider 访问 appSearchData 包
【发布时间】:2010-12-09 10:45:08
【问题描述】:

一个活动应该能够像这样向内容提供者提供上下文信息:

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

来自提供者的搜索建议和结果应限制为“类别”,但我找不到从我的 ContentProvider 访问 appSearchData 包的位置。

【问题讨论】:

标签: android search android-contentprovider


【解决方案1】:

将此用于 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;
}

这是你的可搜索类:

Bundle b = intent.getBundleExtra(SearchManager.APP_DATA);

【讨论】:

  • @bitbox 抱歉回复晚了,您只需调用“getIntent()”方法即可:Intent intent = getIntent() in the onCreate
  • 问题是关于返回搜索建议的内容提供者,而不是搜索活动。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-18
  • 1970-01-01
  • 2017-11-09
  • 2021-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多