1

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)

Silence Android Phone in Java

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.

Community
  • 1
  • 1
user
  • 121
  • 12

1 Answers1

0

Have you tried adding this code?

int streams = AudioManager.STREAM_ALARM|AudioManager.STREAM_DTMF|AudioManager.STREAM_MUSIC|
              AudioManager.STREAM_NOTIFICATION|
              AudioManager.STREAM_RING|AudioManager.STREAM_SYSTEM|
              AudioManager.STREAM_VOICE_CALL;
audioManager.AdjustVolume(streams,ADJUST_MUTE);

According to the flag, you can mute specific streams..in this code, I muted them all

Ilan Kutsman
  • 469
  • 3
  • 9
  • Unfortunately that didn't work either. Maybe it is just a bug in the Android shell of Sony. Although I can't find any clues that points towards that. – user Feb 13 '16 at 15:37