0

在我的应用程序中,有一个功能可以通过请求打开 Search Google 应用程序:

    Intent intent = new Intent(Intent.ACTION_SEARCH);

    intent.setClassName("com.google.android.googlequicksearchbox", "com.google.android.googlequicksearchbox.SearchActivity");
 
    intent.putExtra(SearchManager.QUERY, string);

    activity.startActivity(intent);

上面的代码以前可以工作,我记得,现在不一样了,因为搜索活动打开了,但搜索字段只是填充了字符串值,但搜索没有开始,所以用户必须按 Enter按钮。列出了基于该字符串的建议。

它似乎取决于 Android 版本,或者最近的一些更新,也许?我认为行为是不同的。我尝试在智能手机上使用 Android 11。

我还尝试将 \n 附加到字符串,但只显示尾随空格。

如果使用 ACTION_WEB_SEARCH 意图,则搜索功能本身不同,仅在 web 上执行,不包括本地结果,但搜索已有效启动,用户尚未确认。

有什么解决方法吗?我想使用 ACTION_SEARCH 意图。

4

0 回答 0