Reputation: 8978
I'm making an application for Android API 11 (or newer). I'm trying to get callbacks from a TTS engine, but there a problem appears. I've tried to set a listener using setOnUtteranceProgressListener()
method but Eclipse says that requires API 15 or newer (and throws a compilation error), so next I've tried to use setOnUtteranceCompletedListener()
but than it says "This method was deprecated in API level 15". What should I use to make it compatible with API 11 and higher?
Upvotes: 0
Views: 585
Reputation: 139
You can use this code:
TextToSpeech tts = new TextToSpeech(this, this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
// API > 15
tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onStart(String utteranceId) {
// do something
}
@Override
public void onDone(String utteranceId) {
// do something
}
@Override
public void onError(String utteranceId) {
// do something
}
});
} else {
// API < 15
tts.setOnUtteranceCompletedListener(new TextToSpeech.OnUtteranceCompletedListener() {
@Override
public void onUtteranceCompleted(String utteranceId) {
// do something
}
});
}
Upvotes: 0
Reputation: 5935
You either use the deprecated methods or do one of the depending on which Android version the device is running. You can look at Build.VERSION.SDK_INT.
Upvotes: 1