SoulRayder
SoulRayder

Reputation: 5166

AudioManager returning stream volume as zero even when phone volume is not zero

I am trying to enforce some behaviour in my app if phone is not in zero volume mode (silent mode or vibrate mode).

This is my code:

audioManager =  (AudioManager)getSystemService(Context.AUDIO_SERVICE);
if (audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0 )
                {
                    Log.d("Logmessage"," Audio stream ring volume : "+ audioManager.getStreamVolume(AudioManager.STREAM_RING));

                    return;
                }

//Further logic

However, the logic after the if block never gets executed as I am always getting the ringer stream volume as zero. I also checked the ringer mode (it always returns RINGER_MODE_VIBRATE).

Interestingly, I am observing this only in Kitkat OS and for my Motorola and lenovo phones. The logic works perfectly fine in my Samsung and Lenovo phones having Android 6.0.

Anyone please tell me what I am missing and what is wrong with my check? I am using this logic within a Service

Upvotes: 0

Views: 1057

Answers (1)

You Kim
You Kim

Reputation: 2815

TIP: You can check current volume and selected device in audio system

adb shell dumpsys audio
...
- STREAM_RING:
   Muted: true
   Min: 0
   Max: 7
   Current: 1 (earpiece): 5, 2 (speaker): 0, 20 (bt_sco_hs): 5, 80 (bt_a2dp): 5, 40000000 (default): 5
   Devices: speaker
...
Ringer mode:
- mode (internal) = VIBRATE
- mode (external) = VIBRATE
- ringer mode affected streams = 0x126 (STREAM_SYSTEM,STREAM_RING,STREAM_NOTIFICATION,STREAM_DTMF)
- ringer mode muted streams = 0x126 (STREAM_SYSTEM,STREAM_RING,STREAM_NOTIFICATION,STREAM_DTMF)
- delegate = ZenModeHelper

Upvotes: 1

Related Questions