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>
You should check if a recognition app is installed first:
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
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.
If you have a device with custom ROM:
Download: Google App.apk [https://www.apkmirror.com/apk/google-inc/google-search/] or .app if you have acess to Google Play Store.
Install using adb command "adb install path_to_apk" [https://developer.android.com/studio/command-line/adb.html?hl=en#move])
If it does not work, download also: Google Play Services.apk
I know this question is over 1 year, but I had problems with a robot (with Android OS 4.4.4 API 19 and custom ROM) and having used RecognizerIntent helped me a lot.