【问题标题】:No Activity found to handle Intent { act=android.speech.action.RECOGNIZE_SPEECH (has extras) }未找到处理 Intent { act=android.speech.action.RECOGNIZE_SPEECH 的活动(有附加功能)}
【发布时间】:2012-02-28 10:00:04
【问题描述】:

以下代码中抛出了异常:

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,比如导入一些库或其他~
非常感谢。

【问题讨论】:

  • 问题的“语音搜索应用”链接目前已损坏 (404)。

标签: android google-voice


【解决方案1】:

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

作为

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);

}

https://market.android.com/details?id=APP_PACKAGE_NAME中的APP_PACKAGE_NAME替换为市场上的语音识别应用包名

【讨论】:

  • 感谢您的回复 vipin,但我可以将语音模块添加为我的 apk 的一部分。
  • 是的,你可以肯定,但为此你必须自己写下整个代码
  • @vipin 当你说 APP_PACKAGE_NAME 时,你知道有默认的吗?我的意思是它在我的其他设备上运行良好,但对于 Sony Experia Mini,语音识别不起作用。所以我想将用户指向谷歌的默认语音识别。
  • Igor 没有像谷歌默认语音搜索这样的东西,但你可以使用谷歌的应用程序来满足你的要求,请试试这个 com.google.android.voicesearch
  • 此包语音搜索不再可用。
【解决方案2】:

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)));
    }
}

【讨论】:

    猜你喜欢
    • 2013-02-03
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多