Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AudioManager setStreamVolume without flags

The Android AudioManager has the method public void setStreamVolume (int streamType, int index, int flags).

I don't want to use any flags as they all are used to enable feedback. I don't want vibration, or a UI pop-up, or a hint of any sort. I don't want to cancel the currently playing ringtone. I just want to set the stream volume, how can I do this?

If I change the volume while there is a ringtone playing, is the ringtone's volume affected or does the change only affect future ringtones?

This is the closest post I could find on the topic, but it doesn't answer the question: What do the the flag parameter means and range of possible min and max of droid device

like image 779
DarkMatterMatt Avatar asked Dec 02 '18 10:12

DarkMatterMatt


1 Answers

To not set any flags, pass the integer 0 into the flags parameter.

Kotlin example:

val am = getSystemService(Context.AUDIO_SERVICE) as AudioManager
am.setStreamVolume(AudioManager.STREAM_NOTIFICATION, volume, 0)


Possible flags include (source):

FLAG_SHOW_UI                  = 1 << 0;
FLAG_ALLOW_RINGER_MODES       = 1 << 1;
FLAG_PLAY_SOUND               = 1 << 2;
FLAG_REMOVE_SOUND_AND_VIBRATE = 1 << 3;
FLAG_VIBRATE                  = 1 << 4;
FLAG_FIXED_VOLUME             = 1 << 5;
FLAG_BLUETOOTH_ABS_VOLUME     = 1 << 6;
FLAG_SHOW_SILENT_HINT         = 1 << 7;
FLAG_HDMI_SYSTEM_AUDIO_VOLUME = 1 << 8;
FLAG_ACTIVE_MEDIA_ONLY        = 1 << 9;
FLAG_SHOW_UI_WARNINGS         = 1 << 10;
FLAG_SHOW_VIBRATE_HINT        = 1 << 11;
FLAG_FROM_KEY                 = 1 << 12;

This pattern shows that each bit in the integer represents a different flag. This (confirmed by testing) means that passing 0 as the flags parameter to setStreamVolume represents no flags being set.

like image 60
DarkMatterMatt Avatar answered Nov 12 '22 05:11

DarkMatterMatt