Closed cawoolf closed 1 year ago
Another one solved by chat GPT
To access the device's media volume and set it programmatically in your Android app, you can use the AudioManager class.
Here are the steps to follow:
Add the following permission to your AndroidManifest.xml file: xml Copy code
In your activity's onCreate() method, create an instance of the AudioManager class: java Copy code AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); To get the current media volume, use the getStreamVolume() method of the AudioManager class: java Copy code int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); To set the media volume, use the setStreamVolume() method of the AudioManager class: java Copy code audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, desiredVolume, 0); where desiredVolume is the value you want to set for the media volume.
So, to set the media volume on launch of your app, you can add the above code to your activity's onCreate() method, and pass the desired volume value as an argument to the setStreamVolume() method.
Acts like a bug, if the media is turned down for whatever reason, you can't hear the TTS. Breaks the experience.