Read out Alarm volume

356 views Asked by At

I try to read out the Alarm volume the following way, but I always get wrong values. The ringer volume is always correct!! That happens on every Smartphone, HTC, Samsung, Sony and even on the virtual device. What could be the problem?

private AudioManager amanager;

@Override
public void onCreate(Bundle savedInstanceState) 
{

    amanager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);

}



int volume = 3;
int alarm = 3;

try{
    volume = amanager.getStreamVolume(amanager.getStreamVolume(AudioManager.STREAM_RING));
    alarm = amanager.getStreamVolume(amanager.getStreamVolume(AudioManager.STREAM_ALARM));
    Log.i("!!!!!!!!!!", "Activity!!,  Volume ringer: " + volume + " Vol Alarm: " + alarm);

}catch(IllegalArgumentException e){}
1

There are 1 answers

0
TDG On BEST ANSWER

I was getting wrong values for the ringer volume. The method getStreamVolume (int streamType) gets an int and returns int. When you write:

alarm = amanager.getStreamVolume(amanager.getStreamVolume(AudioManager.STREAM_ALARM));

you're actually getting the volume of the alarm (lets say it is X), and then passing to alarm the value alarm = amanager.getStreamVolume(X);

so the result is unexpected.
change the values of volume and alarm to -

volume = amanager.getStreamVolume(AudioManager.STREAM_RING);
alarm = amanager.getStreamVolume(AudioManager.STREAM_ALARM);