I am trying to get some functionality of my Android App working, however the AudioManager doesn't seem to silence my phone. No matter what I do.
This is the code I have right now:
try {
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setRingerMode(0);
} catch (Exception ex) {
Log.e("Error", ex.getMessage());
}
I've already tried these solutions:
Android audiomanager - I want to set silent mode, but applied the priority mode (lollipop)
And a couple more which indicated that I should try something with the "setStreamVolume" property. But that didn't solve the problem either, because then my phone would still vibrate when receiving a text or phone call.
These are the permissions in my manifest:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
I've turned off the error message for the "write_secure_settings" as this seems to be a system app setting.
The phone I am currently using for testing is my Sony Z5 Compact running Android 5.1.1. Haven't tried the code on my old galaxy s4 running 4.4.2.
Any suggestions on what to try next.