Wednesday, 15 June 2011

How to inhibit "Loud music may harm your hearing..." warning in Android -



How to inhibit "Loud music may harm your hearing..." warning in Android -

i have android application samsung tablet uses external device draws powerfulness tablet headphone jack. when external device powered on (by programmatically maxing out volume), android briefly displays warning popup saying: "loud music may harm hearing if hear long..." message not displayed.

here's offending line of code:

maudiomgr.setstreamvolume(audiomanager.stream_music, maudiomgr.getstreammaxvolume(audiomanager.stream_music), 0);

it's not alternative turn halfway. in fact, i've seen tablet display warning (when changing volume hand) on volume settings lower max setting.

and yes, record original volume, , restore when we're done external device.

thanks suggestions.

i know question quite old, ran across issue myself. figured add together answers given found in case helps else happens upon this.

one of posts here mentions warning not in aosp, not true. please reference volumepanel::safteywarning class here: volumepanel::safetywarning

once peruse through safetywarning class you'll notice there hidden method within of audiomanager class called disablesafemediavolume. can, through reflection, invoke hidden method enough, if you'll security exception requires scheme permission "android.permission.status_bar_service".

so... said, dialog far can tell, cannot programmatically suppressed unless have scheme permission.

what ended doing blessing of product management cache volume setting in sharedpreferences , reset cache when our application starts. if happens above threshold warning dialog warning shown , user have press ok volume setting want, @ to the lowest degree won't have manually reset volume themselves.

a couple of other notes on why don't see dialog. see if have headphones (or earbuds, or wired headset) plugged device , effort set media volume stream on threshold (on samsung galaxy tab threshold 60%). if press ok @ dialog not shown 1 time again unless either restart device or unplug headphones , plug them in (with volume set @ or above threshold).

hope helps someone.

android

No comments:

Post a Comment