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