Callback invocation in Android when Google Assistant starts listening

15 Views Asked by At

One of the functionality in my Android app is it starts playing media received from Backend server. It uses MediaPlayer callbacks and functions to handle playing, stopping and pausing the Audio speak by the app. It also use AudioManager.OnAudioFocusChangeListener to handle focus changes. I am getting a callback of AudioManager.AUDIOFOCUS_LOSS_TRANSIENT when Google Assistant starts to listen and speak. I am able to control the app media stop based on this callback. In other case when Google assistant is already speaking I am not able to get any callback ? What things can be used to check already Google assistant is speaking/listening so that I can skip playing my app audio

I tried overriding inside MainActivity

 override fun onProvideAssistContent(outContent: AssistContent?) {
        super.onProvideAssistContent(outContent)
        navigationMediaPlayer.stop()
    } 

This basically is called when the user is requesting an assist, to provide references to content related to the current activity. But didn't worked. Still the sound is getting overlapped. How this can be resolved ?

0

There are 0 best solutions below