我创建了一个使用语音识别的应用程序,它适用于大多数手机,但是在新的 Galaxy S IV 和 Galaxy Note II 上它失败了:
java.lang.RuntimeException: Unable to start activity ComponentInfo{<my.pakage.myactivity>/<my.pakage.myactivity>}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.speech.action.RECOGNIZE_SPEECH (has extras) }
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2247)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2297)
at android.app.ActivityThread.access$700(ActivityThread.java:152)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5328)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.speech.action.RECOGNIZE_SPEECH (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1659)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1434)
at android.app.Activity.startActivityForResult(Activity.java:3430)
at android.support.v4.app._HoloActivity.superStartActivity(_HoloActivity.java:717)
at android.support.v4.app._HoloActivity.startActivityForResult(_HoloActivity.java:698)
at android.support.v4.app._HoloActivity.startActivityForResult(_HoloActivity.java:689)
at com.ltandfumbles.soundoff.activites.Record.speak(Record.java:263)
at com.ltandfumbles.soundoff.activites.Record.onCreate(Record.java:96)
at android.app.Activity.performCreate(Activity.java:5250)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
... 11 more
触发这个的代码是:
void speak() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
//intent.putExtra(RecognizerIntent.EXTRA_PROMPT, metTextHint.getText().toString());
// Given an hint to the recognizer about what the user is going to say
//There are two form of language model available
//1.LANGUAGE_MODEL_WEB_SEARCH : For short phrases
//2.LANGUAGE_MODEL_FREE_FORM : If not sure about the words or phrases and its domain.
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
int noOfMatches = 3;
// Specify how many results you want to receive. The results will be
// sorted where the first result is the one with higher confidence.
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, noOfMatches);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak now");
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 2000);
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 2000);
//Start the Voice recognizer activity for the result.
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
我意识到错误是由于设备上没有合适的应用程序造成的,但我很难相信新设备没有任何语音识别功能。android 4.2.2 中是否有一些我需要考虑的变化?