Question

My goal is to support a functionality that mute phone (possibly with vibrations enabled/disabled), so when a call or sms is received it won't make noise

unmute phone but prompt for "password for unmute".

And this remains valid for any other application, that it ask for password entry before unmute...

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

Was it helpful?

Solution

Previously on Stackoverflow, Android mute/unmute phone.

Those answers discuss both permissions and the coding. Also, tasker can handle everything you're looking to do.

And here's a link to a tutorial.

The code below runs fine in the emulator. When you run it, you can see the mute goes on in the notification area. In addition to the code, I had to add the (uses) permission for android.permission.MODIFY_AUDIO_SETTINGS.

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    AudioManager audio = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);

    audio.setRingerMode(AudioManager.RINGER_MODE_SILENT);

    return true;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top