Android 操作\u WEB\u搜索仅第一次打开正确的搜索查询

Android 操作\u WEB\u搜索仅第一次打开正确的搜索查询,android,android-intent,android-activity,Android,Android Intent,Android Activity,我有一个应用程序可以打开ACTION_WEB_SEARCH意图打开搜索应用程序。它第一次工作正常,但如果活动再次启动,搜索参数不会更改 public static void launchWebSearch(Context context, String query) { Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, query); con

我有一个应用程序可以打开ACTION_WEB_SEARCH意图打开搜索应用程序。它第一次工作正常,但如果活动再次启动,搜索参数不会更改

public static void launchWebSearch(Context context, String query) {
    Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
    intent.putExtra(SearchManager.QUERY, query);
    context.startActivity(intent);
}

上面的代码将第一次打开包含查询的谷歌搜索应用程序。下次调用它时,它仍将打开谷歌搜索应用程序,但查询不会更改,仍将保留旧的搜索结果。

我也无法重现您的错误;我怀疑问题可能在代码的其他地方

只是在黑暗中拍摄,但您可能希望尝试将以下标志添加到您的意图中:

intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

我认为唯一可能导致这种情况的是处理
ACTION\u WEB\u SEARCH
意图的活动的错误实现(例如被声明为
singleInstance
singleTop
,并且未实现
onNewIntent()
)。可能三星设备附带了定制版的搜索应用程序


我建议使用
PackageManager.queryIntentActivities()
,查看是否有其他可能匹配的
ACTION\u WEB\u SEARCH

面临相同问题

经过一些挖掘,我发现从“谷歌搜索”中卸载更新修复了这个问题,因此这确实与谷歌现在有关(谷歌Quicksearch,股票版,工作非常完美)

我通过在搜索意图中添加以下标志来修复它:

    Intent search = new Intent(Intent.ACTION_WEB_SEARCH);
    search.putExtra(SearchManager.QUERY, query);
    // In the latest Google Now version, ACTION_WEB_SEARCH is broken when used with FLAG_ACTIVITY_NEW_TASK.
    // Adding FLAG_ACTIVITY_CLEAR_TASK seems to fix the problem.
    search.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    search.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

我无法复制这个。你在测试什么版本?安卓4.4.2(Galaxy Note 3 ATT)谷歌搜索应用程序的实际版本已经打开。。它只是切换到它,而不是实际搜索传递的查询。确保
strQuery
变量是
public
而不是
static。
否则,在启动新意图时不会保存变量更改。strQuery不是静态的,而是以静态方法传递的(更新了问题)我打印了所有的意图,它只有谷歌搜索:[ResolveInfo{4462bf30 com.google.android.googlequicksearchbox/com.google.android.search.core.google.google.GoogleSearch m=0x108000}]不起作用:(.将继续查找-感谢您的帮助。