I'm using android AudioManager to mute and unmute streams like STREAM_SYSTEM and STREAM_NOTIFICATION, muting is straightforward calling setStreamMute but I'm unable to find an isStreamMuted method.
Looking inside source code I can see it exists so the question is 'how can check if a stream is muted?
I'm working on Android 4.0.4
Reflections are your friend. This 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: The method public boolean isStreamMute (int streamType)
is now accessible in API 23 without using reflection.
The unpleasant answer is that stream mute operates on a per-process basis. So you can safely store the mute state in a static variable somewhere, appropriately wrapped, and track mute state yourself. Speaking from bitter experience. Sometimes you do what you have to do. Why did they do that? That's a more difficult question....
They stripped the method out of android.jar by using hide:
/**
* get stream mute state.
*
* @hide
*/
public boolean isStreamMute(int streamType) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With