1

I'm trying to implement TextToSpeech in my Android Application:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            TTS.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null, null)
        }
        else {
            TTS.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null)
        }

I'm already providing an if clause for the case it's Lollipop or older, but I'm getting the following error:

speak(String!, Int, HashMap<String!, String!>!: Int' is deprecated. Deprecated in Java.

I don't know what I should use instead of TextToSpeech.QUEUE_FLUSH.

Taseer
  • 3,432
  • 3
  • 16
  • 35
didi_o
  • 23
  • 3

1 Answers1

0

It's just a false warning in the IDE that shouldn't be there. For some reason it doesn't see that you did the code correctly as far as checking the API and applying the correct method signature.

Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100
  • It clearly says in the document that the `.speak()` using `HashMap` is deprecated. On what basis can you say that it is just a "false warning in the IDE" ? – Taseer Jul 19 '19 at 16:05
  • It's deprecated *as of API 21*. In case of API < 21, the old method must still be used. So if the project target API is < 21, then the code is correct. – Nerdy Bunz Jul 19 '19 at 20:42
  • @BooberBunz is right. For Lollipop or older, the `speak()` function using `HashMap` must be used. There was also an error in another class where I called the TTS function. Now it's working, so the correct answer is, that it doesn't affect my code. Thank you anyways – didi_o Jul 23 '19 at 08:51