I’m developing an application that can turn off the sound of Android Phone automatically. How can I detect the volume of the sound and turn it off programmatically?
if (hour == myTime.getHour() && minute == myTime.getMinute()) {
if (Settings.getSetMyTime(this))
showNotificationAlarm(R.drawable.icon,
"It's time to work");
///so, i want to add the silet function here..help me, please?
}
Thanks in advance.
Register for
AUDIO_SERVICEand then use theAudioManagerto control the volume up/down or set profiles.Or if you want to listen for changes in the Audio focus then make your Activity
implements AudioManager.OnAudioFocusChangeListener. Override unimplemented method. Create switch that will take care of types of changes.Like:
Or if you want to listen for changes on the audio output, like unplugging the headphones (switching to phone speaker) use
ACTION_AUDIO_BECOMING_NOISYsticky broadcasthttp://developer.android.com/reference/android/media/AudioManager.html#ACTION_AUDIO_BECOMING_NOISY
http://developer.android.com/reference/android/media/AudioManager.html#RINGER_MODE_SILENT
See here
Edit: This is the solution. There was no need to handle AudioFocus but just set different ringer profile or adjusting volume