android.media.AudioManager#isSpeakerphoneOn ( )源码实例Demo

下面列出了android.media.AudioManager#isSpeakerphoneOn ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mollyim-android   文件: WebRtcCallService.java
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);
  }
}
 
源代码2 项目: bcm-android   文件: WebRtcCallService.java
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);
        }
    }
}
 
源代码3 项目: TelePlus-Android   文件: VoIPBaseService.java
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;
}
 
源代码4 项目: TelePlus-Android   文件: VoIPBaseService.java
@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);
			}
		}
	}
}
 
源代码5 项目: TelePlus-Android   文件: VoIPBaseService.java
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;
}
 
源代码6 项目: TelePlus-Android   文件: VoIPBaseService.java
@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);
			}
		}
	}
}
 
源代码7 项目: iGap-Android   文件: ActivityCallViewModel.java
/**
 * 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);
    }
}
 
源代码8 项目: matrix-android-console   文件: CallViewActivity.java
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);
    }
}
 
源代码9 项目: Telegram-FOSS   文件: VoIPBaseService.java
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;
}
 
源代码10 项目: Telegram-FOSS   文件: VoIPBaseService.java
@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);
			}
		}
	}
}
 
源代码11 项目: Telegram   文件: VoIPBaseService.java
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;
}
 
源代码12 项目: Telegram   文件: VoIPBaseService.java
@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);
			}
		}
	}
}
 
源代码13 项目: mollyim-android   文件: WebRtcCallService.java
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;
  }
}
 
源代码14 项目: TelePlus-Android   文件: VoIPBaseService.java
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;
}
 
源代码15 项目: DevUtils   文件: AudioManagerUtils.java
/**
 * 判断是否打开扩音器 ( 扬声器 )
 * @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;
}
 
源代码16 项目: TelePlus-Android   文件: VoIPBaseService.java
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;
}
 
源代码17 项目: Telegram-FOSS   文件: VoIPBaseService.java
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;
}
 
源代码18 项目: Telegram   文件: VoIPBaseService.java
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;
}
 
源代码19 项目: mollyim-android   文件: WebRtcCallService.java
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);
}