Override silent mode and/or media volume
Asked Answered
E

3

2

I want to override the silent mode and/or media volume to make the phone broadcast a loud noise. I know the alarm clock can override silent mode. How do you do this through your app?

Extraneous answered 1/11, 2010 at 17:0 Comment(0)
J
4

Are you asking whether the Alarm Clock app can override silent mode or if code can override silent mode?

The code answer is yes, you can change the silent mode setting via code like this:

AudioManager audio = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
int currentVolume = audio.getStreamVolume(AudioManager.STREAM_RING);
int max = audio.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION);
audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
audio.setStreamVolume(AudioManager.STREAM_RING, max, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
Jilly answered 1/11, 2010 at 18:4 Comment(0)
C
4

I got another way, as the Tony's answer was worked but what happen it will change the profile suppose you put your device into the silent mode and app required to play any sound like alarm tone then it will change your profile silent to ringer mode and then again you need to put into silent mode. Am I right?

So the another solution was you can play the ringtone here snippet given below

int volume = audioManager.getStreamVolume(AudioManager.STREAM_ALARM);
if(volume==0)
volume = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, volume,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
ringtone = RingtoneManager.getRingtone(getApplicationContext(), Uri.parse(ringTonePath));
if(ringtone!=null){
    ringtone.setStreamType(AudioManager.STREAM_ALARM);
    ringtone.play();
    isRinging = true;
}

isRinging set as flag if you want to programatically stop the playing or you can check the by isPlaying() of ringtone to stop playing

going through this I didn't change the current profile and no more code for that

Condole answered 17/3, 2012 at 13:27 Comment(0)
A
-1

Prey is an open source phone tracker app which does this as one if its features - if you don't get a better answer could have a look at the source to see how they did it.

Assamese answered 1/11, 2010 at 17:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.