gpt4 book ai didi

Android Intent 打开应用程序不工作

转载 作者:行者123 更新时间:2023-11-30 03:11:17 24 4
gpt4 key购买 nike

我正在尝试打开 Google 语音搜索应用程序

    Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage("com.google.android.voicesearch");
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
}

这不会启动语音搜索应用程序,但是,如果我使用 com.google.android.apps.maps 作为程序包名称,则会打开 Google map 应用程序。

我不明白为什么语音搜索打不开,即使包名是正确的。

解决方案

Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
startActivity(intent);

请看 Launch Preinstalled App from activity (Google Voice Search) Android有关解决方案的更多信息。

谢谢。

最佳答案

如您所见here , getLaunchIntentForPackage (字符串包名)

Return a "good" intent to launch a front-door activity in a package [...]

The current implementation will look first for a main activity in the category CATEGORY_INFO, next for a main activity in the category CATEGORY_LAUNCHER, or return null if neither are found.

所以,在 Intent 中,类别已经设置好了。如果您手动更改它,则可能违反了 Intent ,因为该类别可能不是经理找到的正确类别。

所以,把那行去掉

i.addCategory(Intent.CATEGORY_LAUNCHER);

关于Android Intent 打开应用程序不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20935855/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com