Can't set microphone mute - Android

2.4k Views Asked by At

I'm trying to mute my microphone in my Android application

audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setMicrophoneMute(true);

I also added the permission in the manifest

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

However, when I speak to my application, the logs return me exactly what I said which means the microphone is not muted.

Even the logs tell me that the mic should be muted. This :

Log.d("Muted ? : ", String.valueOf(audioManager.isMicrophoneMute()));

Display this log :

Muted ? : true

I really don't know what could be the problem. Do you have any idea about that ?

2

There are 2 best solutions below

1
On

I tried the same, i thought the problem was in all devices, but some devices can mute their microphone, i tried the same solution of this answer:

setMicrophoneMute(boolean) doesn't work on some devices

i simulate a press on mute button on the handsfree kit . it worked for me hope it will help you too here is the code:

Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonUp.putExtra(Intent.EXTRA_KEY_EVENT,new KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEYCODE_HEADSETHOOK));
getBaseContext().sendOrderedBroadcast(buttonUp,"android.permission.CALL_PRIVILEGED");
0
On

The Samsung Galaxy Tab 10.1 and Motorola Xoom work as you would expect. Call audioManager.setMicrophoneMute(true) to mute and audioManager.setMicrophoneMute(false) to unmute