-2

I am building a voice recognition app that does something when I say a specific word such as "open" and it opens something etc. but the problem is that my app keep crashing when I run it on my phone (real device) and I tap the speak button. I don't know what else to do? I tried giving it internet and voice recognition permission but it still doesn't help

here is the code in java (android studio)

public class MainActivity extends Activity {

private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;

private TextView resultText;

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button speakButton = (Button) findViewById(R.id.SpeakButton);

    speakButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view)
        {
            startVoiceRecognitionActivity();
        }
    });
}

void startVoiceRecognitionActivity(){
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
    startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}

@Override
protected void onActivityResult (int requestCode,int resultCode, Intent data){
    String wordStr = null;
    String[] words = null;
    String firstWord = null;
    String secondWord = null;
    if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK)
        {
            ArrayList<String> matches = data
                .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            wordStr = matches.get(0);
            words = wordStr.split(" ");
            firstWord = words[0];
            secondWord = words[1];
        }

    if (firstWord.equals("open"))
        {
            resultText = (TextView)findViewById(R.id.ResultText);
            resultText.setText("Results: Open Command Works");
        }
}

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <uses-permission android:name="android.permission.RECORD_AUDIO" />
        <uses-permission android:name="android.permission.INTERNET" />


        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

I look at the log and it said:

08-07 20:12:57.813 14350-14350/? E/BoostFramework: BoostFramework() : Exception_1 = java.lang.ClassNotFoundException: Didn't find class "com.qualcomm.qti.Performance" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib64, /vendor/lib64]] 08-07 20:12:58.509 14350-14350/com.starlinginteractivesoftworks.musiccompanion E/AndroidRuntime: FATAL EXCEPTION: main Process: com.starlinginteractivesoftworks.musiccompanion, PID: 14350 android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.speech.action.RECOGNIZE_SPEECH launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } (has extras) } at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1839) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1531) at android.app.Activity.startActivityForResult(Activity.java:4399) at android.app.Activity.startActivityForResult(Activity.java:4358) at com.starlinginteractivesoftworks.musiccompanion.MainActivity.startVoiceRecognitionActivity(MainActivity.java:55) at com.starlinginteractivesoftworks.musiccompanion.MainActivity$1.onClick(MainActivity.java:43) at android.view.View.performClick(View.java:6205) at android.widget.TextView.performClick(TextView.java:11103) at android.view.View$PerformClick.run(View.java:23653) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Johnny
  • 27
  • 7

1 Answers1

0

The boost framework log is just a warning, no worry about it. The real problem is the

ActivityNotFoundException: No Activity found to handle Intent

It can come from:

  • a poor connectivity
  • the voice app is missing on your phone

Possible solutions

Ensure you have a recognition app installed (see ActivityNotFoundException: No Activity found to handle Intent (RECOGNIZE_SPEECH) for more details).

Try to enable offline mode as explained here:

  1. On your device go to Settings -> Language and Input. Click on icon on Google voice input.
  2. Under ALL tab select the language you want to download.
  3. Once the language package downloaded, you can see it under INSTALLED tab.

Workarounds

Catch the exception and open a webview to download a recognition app:

try{
   ...
}
catch(ActivityNotFoundException e) {
Intent i = new Intent(Intent.ACTION_VIEW,            
   Uri.parse("https://market.android.com/details?id=APP_PACKAGE_NAME"));
startActivity(i);

}

Check that a recognition app is available before the startActivity (see https://stackoverflow.com/a/35290037/2667536):

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
}
Derlin
  • 9,572
  • 2
  • 32
  • 53