I'm working on an APK with a requirement to reset the device volume to a default value after a certain amount of time, however the code I'm using doesn't seem to be doing anything. Currently I'm trying to do so by using the AudioManager.setStreamVolume method like so:
val audioStreamList = arrayOf(
AudioManager.STREAM_MUSIC,
AudioManager.STREAM_ALARM,
AudioManager.STREAM_DTMF,
AudioManager.STREAM_NOTIFICATION,
AudioManager.STREAM_RING,
AudioManager.STREAM_SYSTEM,
AudioManager.STREAM_VOICE_CALL
)
fun setVolume() {
for (stream in audioStreamList) {
// Trying to set device volume to 50% by setting all stream volumes to 50%
val volume = 0.5 * audioManager.getStreamMaxVolume(stream)
audioManager.setStreamVolume(stream, volume, 0)
}
}
I have added this to the AndroidManifest.xml:
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
Some additional details:
- Using Kotlin
- This is an Alexa-enabled device
- After the above code is executed, Alexa thinks the volume is 5 (that's what she says the volume is). However, the actual device volume is still at the last Alexa-set volume.
Any ideas?