Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Android应用程序以编程方式调用Google Now search_Android_Android Intent_Google Now - Fatal编程技术网

从Android应用程序以编程方式调用Google Now search

从Android应用程序以编程方式调用Google Now search,android,android-intent,google-now,Android,Android Intent,Google Now,我有一个文本框和一个按钮。当我点击按钮时,Google Now会被文本框中的文本触发。我正在使用下面的功能启动谷歌现在与文本 public void searchWeb(String query) { Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, query); intent.setFlags(Intent.F

我有一个文本框和一个按钮。当我点击按钮时,Google Now会被文本框中的文本触发。我正在使用下面的功能启动谷歌现在与文本

    public void searchWeb(String query)
    {
      Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
      intent.putExtra(SearchManager.QUERY, query);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
      startActivity(intent);
    }
问题是,我现在只能在谷歌没有运行状态时用我的文本打开它。当它处于运行状态时,Google Now页面会打开,但搜索查询不会更新为最新的查询


我遗漏了什么吗?

进一步调查这个问题,我发现我错误地使用了设置标志的方法。在这里,我必须使用addflags方法而不是setFlags,这样代码就可以正常工作

    public void searchWeb(String query)
    {
      Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
      intent.putExtra(SearchManager.QUERY, query);
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
      startActivity(intent);
    }

你不明白这个问题,你的代码是谷歌现在,我要找的是谷歌助手的代码介绍在像素手机与安卓7.x。