我在我的 Android 应用程序中使用无对话语音输入:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyRecognitionListener listener = new MyRecognitionListener();
sr = SpeechRecognizer.createSpeechRecognizer(this);
sr.setRecognitionListener(listener);
findViewById(R.id.bt1).setOnClickListener(new View.OnClickListener() {
@Override
public void onButtonClick(View v) {
Intent intent = new
Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.query");
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en_US");
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en_US");
intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, "en_US");
sr.startListening(intent);
}
});
}
部分用户反映在魅族 M5 上单击按钮(在 onButtonClick 侦听器中)后应用程序挂起。其他设备没有任何问题。一位魅族 M5 用户发送了以下错误报告:
Stack:
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.view.View$DeclaredOnClickListener.onClick(View.java:4543)
at android.view.View.performClick(View.java:5317)
at android.view.View$PerformClick.run(View.java:21648)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5896)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:948)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:809)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4538)
... 10 more
Caused by: java.lang.SecurityException: Not allowed to bind to service Intent { act=android.speech.RecognitionService cmp=com.mediatek.voicecommand/.service.VoiceWakeupRecognitionService }
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1421)
at android.app.ContextImpl.bindService(ContextImpl.java:1385)
at android.content.ContextWrapper.bindService(ContextWrapper.java:604)
at android.speech.SpeechRecognizer.startListening(SpeechRecognizer.java:287)
at com.TestAPP.MainActivity.onBtClick(Unknown Source)
... 12 more
请问如何用魅族M5解决这个问题?