Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android mute/unmute phone

Tags:

My goal is to support 2 operations:

  • mute phone (possibly with vibrations enabled/disabled), so when a call or sms is received it won't make noise

  • unmute phone and restore the volume to the state before muting phone

How can I do this? What permissions are required in AndroidManifest?

like image 390
Sebastian Nowak Avatar asked Sep 06 '11 09:09

Sebastian Nowak


People also ask

How do I unmute my smartphone?

On iOS and Android mobile devices, you can mute or unmute your microphone even when you are not in Circuit or your device is locked. You need just to tap the microphone icon in the active call notification that is shown in your device's notification center and lock screen.


1 Answers

This is the permission for vibrate into the manifest file

<uses-permission android:name="android.permission.VIBRATE" /> 

this is for to put the device in silent mode with vibrate

AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); 

this is for to put into the ringing mode

AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);  audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); audioManager.setStreamVolume(AudioManager.STREAM_RING, maxVolume, AudioManager.FLAG_SHOW_UI + AudioManager.FLAG_PLAY_SOUND); 
like image 192
Pratik Avatar answered Oct 11 '22 14:10

Pratik