Comment gracieusement arrêt Android Service de l'exécution d'un discours RecognizerIntent?

StackOverflow https://stackoverflow.com//questions/25007390

  •  20-12-2019
  •  | 
  •  

Question

J'ai mis en place une version de la SilentVoiceRecognitionService.

Cependant, j'ai un problème avec le Service n'est pas arrêté correctement dans la mesure où la prochaine fois que l'application est lancée, le service lance un ERROR_RECOGNIZER_BUSY.

Dans le cas où il aide, c'est comment mon service est declated dans le Manifeste:

    <service
        android:name="com.xyz.SilentVoiceRecognitionService"
        android:label="@string/app_name">
    </service>  

Le SilentVoiceRecognitionService est démarré à partir de l'application de service principal (en onStartCommand):

    public int onStartCommand(Intent intent, int flags, int startId) {
    if (mLiveCard == null) {

        [...]

        startService(new Intent(this, SilentVoiceRecognitionService.class));
    }
    return START_STICKY;
}

Ce service est lancé une fois.Voici il de la déclaration dans le fichier Manifeste:

    <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>

Quelqu'un aurait-il une idée pourquoi cela SilentVoiceRecognitionService n'est pas éteint correctement?

Était-ce utile?

La solution 2

Je ne suis toujours pas sûr de savoir pourquoi il y a un reconnaissance écoutant déjà lors du lancement de l'application.Cependant, les tests de son état à Onerror (), annulant le reconnaissance et le redémarrage de l'écoute ont fonctionné pour moi.

Voici le code que j'ai utilisé:

        @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);
    }

Autres conseils

Peut-être essayer de mettre un stopService dans votre onDestroy de votre service ou de l'activité.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top