Why is AudioManager.isStreamMuted unavailable?

I use Android AudioManager to disable and enable streams such as STREAM_SYSTEM and STREAM_NOTIFICATION, muting is a simple call to setStreamMute , but I cannot find the isStreamMuted method.

Looking in the source code, I see it exists , so the question is: "How to check if the stream is disconnected?

I am working on Android 4.0.4

+6
source share
3 answers

The unpleasant answer is that muting a thread works on the basis of each process. That way, you can safely store the mute state in a static variable somewhere, properly wrapped, and track the mute state yourself. Speaking from a bitter experience. Sometimes you do what you must do. Why would they do that? This is a more complicated question ....

+7
source

Reflections are your friend. It worked for me.

try { Method m = AudioManager.class.getMethod("isStreamMute", int.class); isMuted = (Boolean) m.invoke(am, AudioManager.STREAM_MUSIC); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { System.out.println(e); } 

Update: now the public boolean isStreamMute (int streamType) is available in API 23 without using reflection.

+8
source

They removed the method from android.jar using hide:

 /** * get stream mute state. * * @hide */ public boolean isStreamMute(int streamType) { 
+1
source

All Articles