9

The exception was thrown in the following code:

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

I've googled and found that it's because of the voice search app from google is missing on the device I am using. and I could solve the problem by installing the app manually, but how could I get the apk installed programly, like import some library or other~
Thanks a lot.

Bolton
  • 2,226
  • 3
  • 25
  • 29

2 Answers2

9

open link of the application(which you want to use) in web view

as

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

}

replace APP_PACKAGE_NAME in https://market.android.com/details?id=APP_PACKAGE_NAME with the voice rcognition applicatio package name on market

vipin
  • 2,851
  • 4
  • 18
  • 32
  • thanks for your reply vipin, but could I add the voice module as part of my apk. – Bolton Feb 28 '12 at 13:32
  • yes you can for sure but for that you have to write down whole code for this on your own – vipin Feb 28 '12 at 13:34
  • @vipin When you say APP_PACKAGE_NAME, are there default ones you know of? I mean it works fine on my other devices, but for Sony Experia Mini the speech recognition doesn't work. So I would like to point the user to the default speech recognition from Google. – IgorGanapolsky Jun 29 '12 at 17:29
  • 2
    Igor there are not the things like default for voice search from google but you can use app from google to meet you requirement please try this com.google.android.voicesearch – vipin Jul 02 '12 at 06:11
  • This package, voicesearch, is not available anymore. – lubrum Dec 07 '20 at 13:52
7

Vipin's solution works. I personally used this as my APP_PACKAGE_NAME: com.google.android.googlequicksearchbox

So to recap the full solution you would do the following: (I modified it a little to first try the market:// scheme first and then fallback on the https:// if that fails.)

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)));
    }
}
Francois Dermu
  • 4,437
  • 2
  • 22
  • 14