Java Code Examples for android.media.AudioManager#setMicrophoneMute()

The following examples show how to use android.media.AudioManager#setMicrophoneMute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignalAudioManager.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public void startOutgoingRinger(OutgoingRinger.Type type) {
  AudioManager audioManager = AppUtil.INSTANCE.getAudioManager(context);
  audioManager.setMicrophoneMute(false);

  if (type == OutgoingRinger.Type.SONAR) {
    audioManager.setSpeakerphoneOn(false);
  }

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
  } else {
    audioManager.setMode(AudioManager.MODE_IN_CALL);
  }

  outgoingRinger.start(type);
}
 
Example 2
Source File: SignalAudioManager.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public void stop(boolean playDisconnected) {
  AudioManager audioManager = AppUtil.INSTANCE.getAudioManager(context);

  incomingRinger.stop();
  outgoingRinger.stop();

  if (playDisconnected) {
    soundPool.play(disconnectedSoundId, 1.0f, 1.0f, 0, 0, 1.0f);
  }

  if (audioManager.isBluetoothScoOn()) {
    audioManager.setBluetoothScoOn(false);
    audioManager.stopBluetoothSco();
  }

  audioManager.setSpeakerphoneOn(false);
  audioManager.setMicrophoneMute(false);
  audioManager.setMode(AudioManager.MODE_NORMAL);
  audioManager.abandonAudioFocus(null);
}
 
Example 3
Source File: SignalAudioManager.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public void startIncomingRinger(@Nullable Uri ringtoneUri, boolean vibrate) {
  AudioManager audioManager = ServiceUtil.getAudioManager(context);
  boolean      speaker      = !audioManager.isWiredHeadsetOn() && !audioManager.isBluetoothScoOn();

  audioManager.setMode(AudioManager.MODE_RINGTONE);
  audioManager.setMicrophoneMute(false);
  audioManager.setSpeakerphoneOn(speaker);

  incomingRinger.start(ringtoneUri, vibrate);
}
 
Example 4
Source File: SignalAudioManager.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public void startOutgoingRinger(OutgoingRinger.Type type) {
  AudioManager audioManager = ServiceUtil.getAudioManager(context);
  audioManager.setMicrophoneMute(false);

  audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

  outgoingRinger.start(type);
}
 
Example 5
Source File: SignalAudioManager.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public void startIncomingRinger() {
  AudioManager audioManager = AppUtil.INSTANCE.getAudioManager(context);
  boolean      speaker      = !audioManager.isWiredHeadsetOn() && !audioManager.isBluetoothScoOn();

  audioManager.setMode(AudioManager.MODE_RINGTONE);
  audioManager.setMicrophoneMute(false);
  audioManager.setSpeakerphoneOn(speaker);

  incomingRinger.start();
}
 
Example 6
Source File: AudioManagerUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 设置是否让麦克风静音
 * @param on {@code true} yes, {@code false} no
 * @return {@code true} success, {@code false} fail
 */
public static boolean setMicrophoneMute(final boolean on) {
    AudioManager audioManager = AppUtils.getAudioManager();
    if (audioManager != null) {
        try {
            audioManager.setMicrophoneMute(on);
            return true;
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "setMicrophoneMute");
        }
    }
    return false;
}