Change volume for one beep only on Android

I am working on a life saving medical app and if the user is in a life threatening situation they need to hear a warning.

When I have a status bar notification or a critical message dialog for a user appears, I need to get their attention. If the volume or ringer volume is low or off, I want to override it just for my warning. I would rather not change my phone settings, just for my one sound that I want to play.

When I try:

AudioManager audioManager = (AudioManager)getSystemService(this.AUDIO_SERVICE);  
audioManager.setStreamVolume(AudioManager.STREAM_RING, 
    audioManager.getStreamMaxVolume(AudioManager.STREAM_RING), 0); 

      

This sets the volume correctly for my stream, but has the side effect of changing the volume of the stream for everyone else.

Is there a way to set the volume for just one song?

+3


source to share


1 answer


It can be set after the song is finished.



AudioManager audioManager = (AudioManager)getSystemService(this.AUDIO_SERVICE);
int current_volume=audioManager.getStreamVolume(AudioManager.STREAM_RING);
audioManager.setStreamVolume(AudioManager.STREAM_RING, 
    audioManager.getStreamMaxVolume(AudioManager.STREAM_RING), 0); 
// Play here
audioManager.setStreamVolum(AudioManager.STREAM_RING,current_volume,0);

      

+2


source







All Articles