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

The following examples show how to use android.media.AudioManager#isSpeakerphoneOn() . 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: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public int getCurrentAudioRoute(){
	if(USE_CONNECTION_SERVICE){
		if(systemCallConnection!=null && systemCallConnection.getCallAudioState()!=null){
			switch(systemCallConnection.getCallAudioState().getRoute()){
				case CallAudioState.ROUTE_BLUETOOTH:
					return AUDIO_ROUTE_BLUETOOTH;
				case CallAudioState.ROUTE_EARPIECE:
				case CallAudioState.ROUTE_WIRED_HEADSET:
					return AUDIO_ROUTE_EARPIECE;
				case CallAudioState.ROUTE_SPEAKER:
					return AUDIO_ROUTE_SPEAKER;
			}
		}
		return audioRouteToSet;
	}
	if(audioConfigured){
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		if(am.isBluetoothScoOn())
			return AUDIO_ROUTE_BLUETOOTH;
		else if(am.isSpeakerphoneOn())
			return AUDIO_ROUTE_SPEAKER;
		else
			return AUDIO_ROUTE_EARPIECE;
	}
	return audioRouteToSet;
}
 
Example 2
Source File: VoIPBaseService.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onSensorChanged(SensorEvent event) {
	if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		if (isHeadsetPlugged || am.isSpeakerphoneOn() || (isBluetoothHeadsetConnected() && am.isBluetoothScoOn())) {
			return;
		}
		boolean newIsNear = event.values[0] < Math.min(event.sensor.getMaximumRange(), 3);
		if (newIsNear != isProximityNear) {
			if (BuildVars.LOGS_ENABLED) {
				FileLog.d("proximity " + newIsNear);
			}
			isProximityNear = newIsNear;
			try{
				if(isProximityNear){
					proximityWakelock.acquire();
				}else{
					proximityWakelock.release(1); // this is non-public API before L
				}
			}catch(Exception x){
				FileLog.e(x);
			}
		}
	}
}
 
Example 3
Source File: VoIPBaseService.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public int getCurrentAudioRoute(){
	if(USE_CONNECTION_SERVICE){
		if(systemCallConnection!=null && systemCallConnection.getCallAudioState()!=null){
			switch(systemCallConnection.getCallAudioState().getRoute()){
				case CallAudioState.ROUTE_BLUETOOTH:
					return AUDIO_ROUTE_BLUETOOTH;
				case CallAudioState.ROUTE_EARPIECE:
				case CallAudioState.ROUTE_WIRED_HEADSET:
					return AUDIO_ROUTE_EARPIECE;
				case CallAudioState.ROUTE_SPEAKER:
					return AUDIO_ROUTE_SPEAKER;
			}
		}
		return audioRouteToSet;
	}
	if(audioConfigured){
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		if(am.isBluetoothScoOn())
			return AUDIO_ROUTE_BLUETOOTH;
		else if(am.isSpeakerphoneOn())
			return AUDIO_ROUTE_SPEAKER;
		else
			return AUDIO_ROUTE_EARPIECE;
	}
	return audioRouteToSet;
}
 
Example 4
Source File: VoIPBaseService.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onSensorChanged(SensorEvent event) {
	if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		if (isHeadsetPlugged || am.isSpeakerphoneOn() || (isBluetoothHeadsetConnected() && am.isBluetoothScoOn())) {
			return;
		}
		boolean newIsNear = event.values[0] < Math.min(event.sensor.getMaximumRange(), 3);
		if (newIsNear != isProximityNear) {
			if (BuildVars.LOGS_ENABLED) {
				FileLog.d("proximity " + newIsNear);
			}
			isProximityNear = newIsNear;
			try{
				if(isProximityNear){
					proximityWakelock.acquire();
				}else{
					proximityWakelock.release(1); // this is non-public API before L
				}
			}catch(Exception x){
				FileLog.e(x);
			}
		}
	}
}
 
Example 5
Source File: VoIPBaseService.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public int getCurrentAudioRoute(){
	if(USE_CONNECTION_SERVICE){
		if(systemCallConnection!=null && systemCallConnection.getCallAudioState()!=null){
			switch(systemCallConnection.getCallAudioState().getRoute()){
				case CallAudioState.ROUTE_BLUETOOTH:
					return AUDIO_ROUTE_BLUETOOTH;
				case CallAudioState.ROUTE_EARPIECE:
				case CallAudioState.ROUTE_WIRED_HEADSET:
					return AUDIO_ROUTE_EARPIECE;
				case CallAudioState.ROUTE_SPEAKER:
					return AUDIO_ROUTE_SPEAKER;
			}
		}
		return audioRouteToSet;
	}
	if(audioConfigured){
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		if(am.isBluetoothScoOn())
			return AUDIO_ROUTE_BLUETOOTH;
		else if(am.isSpeakerphoneOn())
			return AUDIO_ROUTE_SPEAKER;
		else
			return AUDIO_ROUTE_EARPIECE;
	}
	return audioRouteToSet;
}
 
Example 6
Source File: CallViewActivity.java    From matrix-android-console with Apache License 2.0 6 votes vote down vote up
private void refreshSpeakerButton() {
    if ((null != mCall) && mCall.getCallState().equals(IMXCall.CALL_STATE_CONNECTED)) {
        mSpeakerSelectionView.setVisibility(View.VISIBLE);

        AudioManager audioManager = (AudioManager) CallViewActivity.this.getSystemService(Context.AUDIO_SERVICE);
        if (audioManager.isSpeakerphoneOn()) {
            mSpeakerSelectionView.setImageResource(R.drawable.ic_material_call);
        } else {
            mSpeakerSelectionView.setImageResource(R.drawable.ic_material_volume);
        }
        CallViewActivity.this.setVolumeControlStream(audioManager.getMode());

    } else {
        mSpeakerSelectionView.setVisibility(View.GONE);
    }
}
 
Example 7
Source File: ActivityCallViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Sets the speaker phone mode.
 */
private void setSpeakerphoneOn(boolean on) {

    AudioManager audioManager = (AudioManager) G.context.getSystemService(Context.AUDIO_SERVICE);

    boolean wasOn = false;
    if (audioManager != null) {
        wasOn = audioManager.isSpeakerphoneOn();
    }
    if (wasOn == on) {
        return;
    }
    if (audioManager != null) {
        audioManager.setSpeakerphoneOn(on);
    }
}
 
Example 8
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onSensorChanged(SensorEvent event) {
	if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		if (isHeadsetPlugged || am.isSpeakerphoneOn() || (isBluetoothHeadsetConnected() && am.isBluetoothScoOn())) {
			return;
		}
		boolean newIsNear = event.values[0] < Math.min(event.sensor.getMaximumRange(), 3);
		if (newIsNear != isProximityNear) {
			if (BuildVars.LOGS_ENABLED) {
				FileLog.d("proximity " + newIsNear);
			}
			isProximityNear = newIsNear;
			try{
				if(isProximityNear){
					proximityWakelock.acquire();
				}else{
					proximityWakelock.release(1); // this is non-public API before L
				}
			}catch(Exception x){
				FileLog.e(x);
			}
		}
	}
}
 
Example 9
Source File: WebRtcCallService.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void handleWiredHeadsetChange(Intent intent) {
  Log.i(TAG, "handleWiredHeadsetChange...");

  if ((activePeer != null) &&
      (activePeer.getState() == CallState.CONNECTED     ||
       activePeer.getState() == CallState.DIALING       ||
       activePeer.getState() == CallState.RECEIVED_BUSY ||
       activePeer.getState() == CallState.REMOTE_RINGING))
  {
    AudioManager audioManager = ServiceUtil.getAudioManager(this);
    boolean      present      = intent.getBooleanExtra(EXTRA_AVAILABLE, false);

    if (present && audioManager.isSpeakerphoneOn()) {
      audioManager.setSpeakerphoneOn(false);
      audioManager.setBluetoothScoOn(false);
    } else if (!present && !audioManager.isSpeakerphoneOn() && !audioManager.isBluetoothScoOn() && localCameraState.isEnabled()) {
      audioManager.setSpeakerphoneOn(true);
    }

    sendMessage(viewModelStateFor(activePeer), activePeer, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled, isRemoteVideoOffer);
  }
}
 
Example 10
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onSensorChanged(SensorEvent event) {
	if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		if (isHeadsetPlugged || am.isSpeakerphoneOn() || (isBluetoothHeadsetConnected() && am.isBluetoothScoOn())) {
			return;
		}
		boolean newIsNear = event.values[0] < Math.min(event.sensor.getMaximumRange(), 3);
		if (newIsNear != isProximityNear) {
			if (BuildVars.LOGS_ENABLED) {
				FileLog.d("proximity " + newIsNear);
			}
			isProximityNear = newIsNear;
			try{
				if(isProximityNear){
					proximityWakelock.acquire();
				}else{
					proximityWakelock.release(1); // this is non-public API before L
				}
			}catch(Exception x){
				FileLog.e(x);
			}
		}
	}
}
 
Example 11
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public int getCurrentAudioRoute(){
	if(USE_CONNECTION_SERVICE){
		if(systemCallConnection!=null && systemCallConnection.getCallAudioState()!=null){
			switch(systemCallConnection.getCallAudioState().getRoute()){
				case CallAudioState.ROUTE_BLUETOOTH:
					return AUDIO_ROUTE_BLUETOOTH;
				case CallAudioState.ROUTE_EARPIECE:
				case CallAudioState.ROUTE_WIRED_HEADSET:
					return AUDIO_ROUTE_EARPIECE;
				case CallAudioState.ROUTE_SPEAKER:
					return AUDIO_ROUTE_SPEAKER;
			}
		}
		return audioRouteToSet;
	}
	if(audioConfigured){
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		if(am.isBluetoothScoOn())
			return AUDIO_ROUTE_BLUETOOTH;
		else if(am.isSpeakerphoneOn())
			return AUDIO_ROUTE_SPEAKER;
		else
			return AUDIO_ROUTE_EARPIECE;
	}
	return audioRouteToSet;
}
 
Example 12
Source File: WebRtcCallService.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private void handleWiredHeadsetChange(Intent intent) {
    ALog.d(TAG, "handleWiredHeadsetChange...");

    CallState currentState = this.callState.get();
    if (currentState == CallState.STATE_CONNECTED ||
            currentState == CallState.STATE_DIALING ||
            currentState == CallState.STATE_REMOTE_RINGING) {
        AudioManager audioManager = AppUtil.INSTANCE.getAudioManager(this);
        boolean present = intent.getBooleanExtra(EXTRA_AVAILABLE, false);

        if (present && audioManager.isSpeakerphoneOn()) {
            audioManager.setSpeakerphoneOn(false);
            audioManager.setBluetoothScoOn(false);
        } else if (!present && !audioManager.isSpeakerphoneOn() && !audioManager.isBluetoothScoOn() && localCameraState.isEnabled()) {
            audioManager.setSpeakerphoneOn(true);
        }

        if (recipient != null) {
            sendMessage(viewModelStateFor(callState.get()), recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
        }
    }
}
 
Example 13
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public boolean isSpeakerphoneOn(){
	if(USE_CONNECTION_SERVICE && systemCallConnection!=null && systemCallConnection.getCallAudioState()!=null){
		int route=systemCallConnection.getCallAudioState().getRoute();
		return hasEarpiece() ? route==CallAudioState.ROUTE_SPEAKER : route==CallAudioState.ROUTE_BLUETOOTH;
	}else if(audioConfigured && !USE_CONNECTION_SERVICE){
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		return hasEarpiece() ? am.isSpeakerphoneOn() : am.isBluetoothScoOn();
	}
	return speakerphoneStateToSet;
}
 
Example 14
Source File: AudioManagerUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 判断是否打开扩音器 ( 扬声器 )
 * @return {@code true} yes, {@code false} no
 */
public static boolean isSpeakerphoneOn() {
    AudioManager audioManager = AppUtils.getAudioManager();
    if (audioManager != null) {
        try {
            return audioManager.isSpeakerphoneOn();
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "isSpeakerphoneOn");
        }
    }
    return false;
}
 
Example 15
Source File: VoIPBaseService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public boolean isSpeakerphoneOn(){
	if(USE_CONNECTION_SERVICE && systemCallConnection!=null && systemCallConnection.getCallAudioState()!=null){
		int route=systemCallConnection.getCallAudioState().getRoute();
		return hasEarpiece() ? route==CallAudioState.ROUTE_SPEAKER : route==CallAudioState.ROUTE_BLUETOOTH;
	}else if(audioConfigured && !USE_CONNECTION_SERVICE){
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		return hasEarpiece() ? am.isSpeakerphoneOn() : am.isBluetoothScoOn();
	}
	return speakerphoneStateToSet;
}
 
Example 16
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public boolean isSpeakerphoneOn(){
	if(USE_CONNECTION_SERVICE && systemCallConnection!=null && systemCallConnection.getCallAudioState()!=null){
		int route=systemCallConnection.getCallAudioState().getRoute();
		return hasEarpiece() ? route==CallAudioState.ROUTE_SPEAKER : route==CallAudioState.ROUTE_BLUETOOTH;
	}else if(audioConfigured && !USE_CONNECTION_SERVICE){
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		return hasEarpiece() ? am.isSpeakerphoneOn() : am.isBluetoothScoOn();
	}
	return speakerphoneStateToSet;
}
 
Example 17
Source File: VoIPBaseService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public boolean isSpeakerphoneOn(){
	if(USE_CONNECTION_SERVICE && systemCallConnection!=null && systemCallConnection.getCallAudioState()!=null){
		int route=systemCallConnection.getCallAudioState().getRoute();
		return hasEarpiece() ? route==CallAudioState.ROUTE_SPEAKER : route==CallAudioState.ROUTE_BLUETOOTH;
	}else if(audioConfigured && !USE_CONNECTION_SERVICE){
		AudioManager am=(AudioManager) getSystemService(AUDIO_SERVICE);
		return hasEarpiece() ? am.isSpeakerphoneOn() : am.isBluetoothScoOn();
	}
	return speakerphoneStateToSet;
}
 
Example 18
Source File: WebRtcCallService.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private LockManager.PhoneState getInCallPhoneState() {
  AudioManager audioManager = ServiceUtil.getAudioManager(this);
  if (audioManager.isSpeakerphoneOn() || audioManager.isBluetoothScoOn() || audioManager.isWiredHeadsetOn()) {
    return LockManager.PhoneState.IN_HANDS_FREE_CALL;
  } else {
    return LockManager.PhoneState.IN_CALL;
  }
}
 
Example 19
Source File: WebRtcCallService.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private void handleSetEnableVideo(Intent intent) {
  boolean      enable       = intent.getBooleanExtra(EXTRA_ENABLE, false);
  AudioManager audioManager = ServiceUtil.getAudioManager(this);

  if (activePeer == null) {
    Log.w(TAG, "handleSetEnableVideo(): Ignoring for inactive call.");
    return;
  }

  Log.i(TAG, "handleSetEnableVideo(): call_id: " + activePeer.getCallId());

  if (activePeer.getState() != CallState.CONNECTED) {
    enableVideoOnCreate = enable;

    if (enableVideoOnCreate              &&
        !audioManager.isSpeakerphoneOn() &&
        !audioManager.isBluetoothScoOn() &&
        !audioManager.isWiredHeadsetOn())
    {
      audioManager.setSpeakerphoneOn(true);
    }

    return;
  }

  try {
    callManager.setVideoEnable(enable);
  } catch  (CallException e) {
    callFailure("setVideoEnable() failed: ", e);
    return;
  }

  localCameraState = camera.getCameraState();

  if (localCameraState.isEnabled()) {
    lockManager.updatePhoneState(LockManager.PhoneState.IN_VIDEO);
  } else {
    lockManager.updatePhoneState(getInCallPhoneState());
  }

  if (localCameraState.isEnabled() &&
      !audioManager.isSpeakerphoneOn() &&
      !audioManager.isBluetoothScoOn() &&
      !audioManager.isWiredHeadsetOn())
  {
    audioManager.setSpeakerphoneOn(true);
  }

  sendMessage(viewModelStateFor(activePeer), activePeer, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled, isRemoteVideoOffer);
}