找不到处理Intent的活动{act = android.speech.action.RECOGNIZE_SPEECH(有附加内容)}

时间:2012-02-28 10:00:04

标签: android google-voice

以下代码抛出了异常:

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
      RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);.

我用谷歌搜索,发现这是因为谷歌的the voice search app在我使用的设备上丢失了。我可以通过手动安装应用程序来解决问题,但是如何才能在程序上安装apk,比如导入一些库或其他〜 非常感谢。

2 个答案:

答案 0 :(得分:7)

在Web视图中打开应用程序(您要使用的)链接

作为

try{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
      RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);.
}
catch(ActivityNotFoundException e)
{
Intent browserIntent = new Intent(Intent.ACTION_VIEW,   Uri.parse("https://market.android.com/details?id=APP_PACKAGE_NAME"));
startActivity(browserIntent);

}

使用市场上的语音rcognition应用程序包名称替换https://market.android.com/details?id=APP_PACKAGE_NAME中的APP_PACKAGE_NAME

答案 1 :(得分:3)

Vipin的解决方案有效。 我个人将此用作我的APP_PACKAGE_NAME: com.google.android.googlequicksearchbox

因此,为了回顾完整的解决方案,您将执行以下操作:(我先修改了一点,先尝试market://方案,然后再回到https://,如果失败的话。)

try {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
      RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
    startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);.
} catch(ActivityNotFoundException e) {
    String appPackageName = "com.google.android.googlequicksearchbox";
    try {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
    } catch (android.content.ActivityNotFoundException anfe) {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
    }
}