简体   繁体   English

从活动(Google语音搜索)Android启动预安装的应用程序

[英]Launch Preinstalled App from activity (Google Voice Search) Android

I am trying to use the following code to launch Google Voice Search from my app. 我正在尝试使用以下代码从我的应用启动Google语音搜索。 It works fine on the Nexus One where Google Voice Search is a downloaded App, however it does not work on my Galaxy Nexus where it comes preinstalled. 在已下载Google语音搜索的Nexus One上,它可以正常运行,但在预装了它的我的Galaxy Nexus上,它无法正常工作。 when it gets to the getLaunchIntentForPackage, the result is NULL. 当到达getLaunchIntentForPackage时,结果为NULL。 Can anyone help out? 有人可以帮忙吗?

Intent i = new Intent(Intent.ACTION_MAIN);
    PackageManager manager = getPackageManager();
    try {
        i = manager.getLaunchIntentForPackage("com.google.android.voicesearch");
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    startActivity(i);

I ran into the exact same problem. 我遇到了完全相同的问题。 It seems to be caused by the way google has packaged up the voice component in ICS. 这似乎是由Google在ICS中打包语音组件的方式引起的。 It's not a standalone app anymore. 它不再是一个独立的应用程序。 It's integrated into the search bar through the general search app. 它通过常规搜索应用程序集成到搜索栏中。

The fix is really easy: 解决方法非常简单:

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

I found this through this tutorial that's more about general speech recognition: http://www.jameselsey.co.uk/blogs/techblog/android-how-to-implement-voice-recognition-a-nice-easy-tutorial/ 我通过本教程发现了更多有关一般语音识别的内容: http : //www.jameselsey.co.uk/blogs/techblog/android-how-to-implement-voice-recognition-a-nice-easy-tutorial/

There's some code in there to verify that the voice recognizer is installed: 那里有一些代码可以验证是否安装了语音识别器:

PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(
    new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    if (activities.size() == 0)
    {
        speakButton.setEnabled(false);
        speakButton.setText("Recognizer not present");
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM