Android, Silent mode notification - android

In my android app I need to know, whenever the user is in Phone options mode (the one that appears when you hold down the power button for a while), and pushes the 'Silent mode' button. I have found that Airplane mode is linked to the ACTION_AIRPLANE_MODE_CHANGED. But I can not find any action event for the 'Silent mode' button?

The AudioManager provides a getRingerMode() method which can be used to determine the current state.
In your case you have to query the returned value for AudioManager.RINGER_MODE_SILENT, so something like
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
if (am.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
// do something neat here
}
In combination with AudioManager's RINGER_MODE_CHANGED_ACTION this should work for you

Related

Turn off ring tone temporarily

When someone calls, my app will turn off the ringing tone in order not to distract the user. So could you please tell me how to turn off the ringing sound in Android?
EDIT:
It seems I will need to use this one :http://developer.android.com/reference/android/media/Ringtone.html
I think I've found the solution. In case someone else needs it, I copy my solution here:
AudioManager manager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
manager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
There is a manager class called AudioManager which controls the audios and such. And it has a instance method setRingerMode(int mode) which accepts a integer flag.
Once you're done with the silence, you can change the status of the ring tone by passing in this flag RINGER_MODE_NORMAL

Adding mute button to application in android?

I my game application am using musics. I need mute and unmute button to put mob i silent mode.
Music runs in every activity like playing game and checking score.But mute button is added in menu activity.
I googled didn't get any exact result.
Use audio manager and set volume
AudioManager audioManager = (AudioManager) getSystemService(ctx.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
I'd choose to set the volume to 0 (mute) or 1 (unmute) with MediaPlayer.setVolume(float volumeLeft, float volumeRight). Also preserves the users volume settings. Trigger by Button is easily achieved with onClickListener().

setRingerMode to normal not working

I have seen a lot of questions about ringer mode. Nothing seems to give me a clue on the problem I am facing. I have set ringer mode to the normal RING mode for a service that gets started in the foreground. Unfortunately that doesnt seem to change the phone's ringer mode if it was on silent or vibrate in the first place. However, if put the same piece of code behind a button on an activity then it works.
The above described case happens only in Android 4.0.4 (ICS) but not in FR 2.2. Any clue on how to get around this? Here's my code:
AudioManager audioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
I have figured out why it didnt work on my phone. I had an other app called Flip Silent that interfered with the working of my app. After everytime I set the Audio Manager to ringer mode, it's service set it it back to the exisiting mode leading me to think it wasnt working.
it was difficult to debug as the logs didnt lead me in any direction. But a flicker on my home screen lead me to find this out. I uninstalled the flip silent app and everything worked!!
I also face the same problem so, I slove that this way.
int getMediaValue = audioManager.getStreamVolume(audioManager.STREAM_RING);
int setVolume = getMediaValue - 1;
// This was work for ring volume
audioManager.setStreamVolume(audioManager.STREAM_RING, setVolume, AudioManager.FLAG_SHOW_UI );
So you can try this way :)

How to implement Phonestatelistener in an activity

I have certain data which i got, when user fill a form in an activity. There is an option Mode where user can select RING or VIBRATE.
So my question is how could i actually implement it in my activity, I see various examples on Telephony manager and phonestatelistener
http://marakana.com/forums/android/examples/62.html.
http://www.tutorialforandroid.com/2009/01/get-phone-state-when-someone-is-calling_22.html
but its hard to implement it in my application,i have data in text form only and dont know how to use this data to switch it from one mode to another. Please tell me in terms of coding example.
phone state listener doesnt determine the ring or vibrate mode - it is for the call status (idle, ring, offhook)
to get the ring/vibrate/silent stau use Audiomanager
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.getRingerMode();// returns AudioManager.RINGER_MODE_VIBRATE or AudioManager.RINGER_MODE_SILENT or AudioManager.RINGER_MODE_NORMAL
// to set ringer mode
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);

Android - Toggle Notification volume programmatically

A Checkbox found in the Ringer Volume settings that allows you
to set a separate Notification volume and incoming call volume
Is there a way to Check/Uncheck the Check box for Notification volume programmatically.
There is a hidden but editable preference in the Settings.System class that determines whether the notification volume is tied to the ringer volume.
It's called NOTIFICATIONS_USE_RING_VOLUME and is marked in the source code as hidden, with the well-commented reason that it will be removed from the platform at some point in the future.
The setting has an integer value of 0 if ringer and notification volumes are independent; 1 otherwise.
I don't recall seeing an API to do this, but you could try altering the notification (or ringer) volume programmatically to see whether that lets it "break free" of the ringer volume.
See AudioManager.adjustStreamVolume(STREAM_NOTIFICATION, ADJUST_RAISE, 0).

Categories

Resources