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){}
I was getting wrong values for the ringer volume. The method
getStreamVolume (int streamType)
gets anint
and returnsint
. When you write:you're actually getting the volume of the alarm (lets say it is X), and then passing to
alarm
the valuealarm = amanager.getStreamVolume(X);
so the result is unexpected.
change the values of
volume
andalarm
to -