1

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 ?

Antoine Delia
  • 1,728
  • 5
  • 26
  • 42

2 Answers2

1

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");
Community
  • 1
  • 1
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
  • Thanks for your answer. I tried to copy this code into my onCreate() method but my application can still uses the microphone... – Antoine Delia Jun 11 '15 at 08:15
0

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

Brinda Rathod
  • 2,693
  • 1
  • 20
  • 32