Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActivityNotFoundException: No Activity found to handle Intent (RECOGNIZE_SPEECH)

I'm trying to make an app using the voice recognizer. This is a piece of my code:

public class Habla extends Activity{

   private static int code = 123;
   ...
   public void escuchar()
   {
       Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
       intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, languageModel);

       intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, numberResults);
       startActivityForResult(intent, code);
    }
...
}

The error is the following:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.speech.action.RECOGNIZE_SPEECH (has extras) }

Why does it happen? .Habla is a class which is run pushing a button in .MainActivity, so the AndoridManifest is:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.emiliomorillanieto.practica3" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".Habla"
            android:parentActivityName=".MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
   </application>
</manifest>
like image 994
user3529582 Avatar asked Feb 09 '16 10:02

user3529582


2 Answers

You should check if a recognition app is installed first:

PackageManager manager = context.getPackageManager();
List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0);
    if (infos.size() > 0) {
         //Then there is application can handle your intent
    }else{
         //No Application can handle your intent
    }
like image 196
malrok44 Avatar answered Nov 15 '22 20:11

malrok44


The reason is voice search app from google is missing on the device you are using. You can solve the problem by manually installing it on your device. But there is another way to do so. That's opening the link of the app in a webview like following

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 your_browser_intent = new Intent(Intent.ACTION_VIEW,         

    Uri.parse("https://market.android.com/details?id=APP_PACKAGE_NAME"));
    startActivity(your_browser_intent);
}

You can also do it by coding and not using webview but that's a lot of work and you need to write a whole bunch of code. So, I think using a webview is pretty much ok.

like image 24
Zahan Safallwa Avatar answered Nov 15 '22 20:11

Zahan Safallwa