Вопрос

For some reason I can't call a method that contains PhoneCallListener from onutteranceCompleted. There are no error messages, it just seems to stop executing the script. I've added some Logs and it gets to the "here" log in setUpPhone with PhoneCallListener. Without PhoneCallListener it will get to the final log "phone set up". Here is example code of how I have it implemented.

@Override
public void onInit(int status)
{
    if(status == TextToSpeech.SUCCESS)
    {
        tts.setOnUtteranceCompletedListener(this);
        int result = tts.setLanguage(Locale.US);

        if(result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED)
        {
            //Language not supported
        }
        else
        {
            speakOut();
        }
    }

}

private void speakOut()
{
    HashMap<String, String> myHashAlarm = new HashMap<String, String>();
    myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM));
    myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "Text to Speech");
    tts.speak("blah blah", TextToSpeech.QUEUE_FLUSH, myHashAlarm);
}

@Override
public void onDestroy()
{
    if(tts != null)
    {
        tts.stop();
        tts.shutdown();
    }

    super.onDestroy();
}

public void onUtteranceCompleted(String utteranceId)
{
    Log.i("TEST", utteranceId);
    setUpPhone();
    Log.i("TEST", "phone set up"); //this is never reached
}

private void setUpPhone()
{
    Log.i("TEST", "here");

    PhoneCallListener phoneListener = new PhoneCallListener(); //If I remove this line, the log "phone set up" displays.
}
Это было полезно?

Решение

I don't know why PhoneCallListener stops execution, however I solved this by putting "phoneListener = new PhoneCallListener();" in the onCreate method.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top