음성 RecognizerIntent를 실행하는 Android 서비스를 정상적으로 종료하는 방법은 무엇입니까?
-
20-12-2019 - |
문제
나는 무음음성인식서비스.
그러나 다음에 애플리케이션을 시작할 때 서비스에서 ERROR_RECOGNIZER_BUSY가 발생할 정도로 서비스가 제대로 종료되지 않는 문제가 있습니다.
도움이 될 경우를 대비하여 매니페스트에 내 서비스가 선언된 방법은 다음과 같습니다.
<service
android:name="com.xyz.SilentVoiceRecognitionService"
android:label="@string/app_name">
</service>
SilentVoiceRecognitionService는 애플리케이션 기본 서비스(onStartCommand)에서 시작됩니다.
public int onStartCommand(Intent intent, int flags, int startId) {
if (mLiveCard == null) {
[...]
startService(new Intent(this, SilentVoiceRecognitionService.class));
}
return START_STICKY;
}
해당 서비스는 한 번 시작됩니다.매니페스트 파일의 선언은 다음과 같습니다.
<service
android:name="com.xyz.XYZService"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="@xml/voice_trigger_start" />
</service>
이 SilentVoiceRecognitionService가 제대로 종료되지 않는 이유를 아는 사람이 있습니까?
해결책 2
앱을 시작할 때 이미 듣는 인식기가 있는지 모르겠습니다.그러나 OnError ()의 상태를 테스트하여 인식기를 취소하고 듣기를 재시작하는 것은 저에게 일했습니다.
여기에 사용 된 코드가 있습니다.
@Override
public void onError(int arg0) {
String mError = "";
switch (arg0) {
case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
mError = " network timeout";
break;
case SpeechRecognizer.ERROR_NETWORK:
mError = " network" ;
return;
case SpeechRecognizer.ERROR_AUDIO:
mError = " audio";
break;
case SpeechRecognizer.ERROR_SERVER:
mError = " server";
break;
case SpeechRecognizer.ERROR_CLIENT:
mError = " client";
break;
case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
mError = " speech time out" ;
break;
case SpeechRecognizer.ERROR_NO_MATCH:
mError = " no match" ;
break;
case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:
mError = " recogniser busy" ;
mSpeechRecognizer.cancel();
break;
case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:
mError = " insufficient permissions" ;
break;
default:
mError = "Unknown Error";
}
Log.i(TAG, "Error: " + arg0 + " - " + mError);
mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
}
. 다른 팁
아마도 stopService
귀하의 서비스/활동 onDestroy에서.
제휴하지 않습니다 StackOverflow