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

The following examples show how to use android.media.AudioManager#isBluetoothScoAvailableOffCall() . 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: BluetoothStateManager.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private boolean isBluetoothAvailable() {
    try {
        synchronized (LOCK) {
            AudioManager audioManager = AppUtil.INSTANCE.getAudioManager(context);

            if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
                return false;
            }
            if (!audioManager.isBluetoothScoAvailableOffCall()) {
                return false;
            }

            return bluetoothHeadset != null && !bluetoothHeadset.getConnectedDevices().isEmpty();
        }
    } catch (Exception e) {
        Log.w(TAG, e);
        return false;
    }
}
 
Example 2
Source File: BluetoothStateManager.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private boolean isBluetoothAvailable() {
  try {
    synchronized (LOCK) {
      AudioManager audioManager = ServiceUtil.getAudioManager(context);

      if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) return false;
      if (!audioManager.isBluetoothScoAvailableOffCall())            return false;

      return bluetoothHeadset != null && !bluetoothHeadset.getConnectedDevices().isEmpty();
    }
  } catch (Exception e) {
    Log.w(TAG, e);
    return false;
  }
}
 
Example 3
Source File: AudioManagerUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 检查当前平台是否支持使用 SCO 的关闭调用用例
 * @return {@code true} yes, {@code false} no
 */
public static boolean isBluetoothScoAvailableOffCall() {
    AudioManager audioManager = AppUtils.getAudioManager();
    if (audioManager != null) {
        try {
            return audioManager.isBluetoothScoAvailableOffCall();
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "isBluetoothScoAvailableOffCall");
        }
    }
    return false;
}
 
Example 4
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onCreate() {
	super.onCreate();
	if (BuildVars.LOGS_ENABLED) {
		FileLog.d("=============== VoIPService STARTING ===============");
	}
	AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER)!=null) {
		int outFramesPerBuffer = Integer.parseInt(am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER));
		VoIPController.setNativeBufferSize(outFramesPerBuffer);
	} else {
		VoIPController.setNativeBufferSize(AudioTrack.getMinBufferSize(48000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT) / 2);
	}
	try {
		cpuWakelock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "telegram-voip");
		cpuWakelock.acquire();

		btAdapter=am.isBluetoothScoAvailableOffCall() ? BluetoothAdapter.getDefaultAdapter() : null;

		IntentFilter filter = new IntentFilter();
		filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
		if(!USE_CONNECTION_SERVICE){
			filter.addAction(ACTION_HEADSET_PLUG);
			if(btAdapter!=null){
				filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
				filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
			}
			filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
		}
		registerReceiver(receiver, filter);

		soundPool = new SoundPool(1, AudioManager.STREAM_VOICE_CALL, 0);
		spConnectingId = soundPool.load(this, R.raw.voip_connecting, 1);
		spRingbackID = soundPool.load(this, R.raw.voip_ringback, 1);
		spFailedID = soundPool.load(this, R.raw.voip_failed, 1);
		spEndId = soundPool.load(this, R.raw.voip_end, 1);
		spBusyId = soundPool.load(this, R.raw.voip_busy, 1);

		am.registerMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class));

		if(!USE_CONNECTION_SERVICE && btAdapter!=null && btAdapter.isEnabled()){
			int headsetState=btAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
			updateBluetoothHeadsetState(headsetState==BluetoothProfile.STATE_CONNECTED);
			//if(headsetState==BluetoothProfile.STATE_CONNECTED)
			//	am.setBluetoothScoOn(true);
			for (StateListener l : stateListeners)
				l.onAudioSettingsChanged();
		}

	} catch (Exception x) {
		if (BuildVars.LOGS_ENABLED) {
			FileLog.e("error initializing voip controller", x);
		}
		callFailed();
	}
}
 
Example 5
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onCreate() {
	super.onCreate();
	if (BuildVars.LOGS_ENABLED) {
		FileLog.d("=============== VoIPService STARTING ===============");
	}
	AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER)!=null) {
		int outFramesPerBuffer = Integer.parseInt(am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER));
		VoIPController.setNativeBufferSize(outFramesPerBuffer);
	} else {
		VoIPController.setNativeBufferSize(AudioTrack.getMinBufferSize(48000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT) / 2);
	}
	try {
		cpuWakelock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "telegram-voip");
		cpuWakelock.acquire();

		btAdapter=am.isBluetoothScoAvailableOffCall() ? BluetoothAdapter.getDefaultAdapter() : null;

		IntentFilter filter = new IntentFilter();
		filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
		if(!USE_CONNECTION_SERVICE){
			filter.addAction(ACTION_HEADSET_PLUG);
			if(btAdapter!=null){
				filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
				filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
			}
			filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
		}
		registerReceiver(receiver, filter);

		soundPool = new SoundPool(1, AudioManager.STREAM_VOICE_CALL, 0);
		spConnectingId = soundPool.load(this, R.raw.voip_connecting, 1);
		spRingbackID = soundPool.load(this, R.raw.voip_ringback, 1);
		spFailedID = soundPool.load(this, R.raw.voip_failed, 1);
		spEndId = soundPool.load(this, R.raw.voip_end, 1);
		spBusyId = soundPool.load(this, R.raw.voip_busy, 1);

		am.registerMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class));

		if(!USE_CONNECTION_SERVICE && btAdapter!=null && btAdapter.isEnabled()){
			int headsetState=btAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
			updateBluetoothHeadsetState(headsetState==BluetoothProfile.STATE_CONNECTED);
			//if(headsetState==BluetoothProfile.STATE_CONNECTED)
			//	am.setBluetoothScoOn(true);
			for (StateListener l : stateListeners)
				l.onAudioSettingsChanged();
		}

	} catch (Exception x) {
		if (BuildVars.LOGS_ENABLED) {
			FileLog.e("error initializing voip controller", x);
		}
		callFailed();
	}
}
 
Example 6
Source File: VoIPBaseService.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onCreate() {
	super.onCreate();
	if (BuildVars.LOGS_ENABLED) {
		FileLog.d("=============== VoIPService STARTING ===============");
	}
	try {
		AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER)!=null) {
			int outFramesPerBuffer = Integer.parseInt(am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER));
			TgVoip.setBufferSize(outFramesPerBuffer);
		} else {
			TgVoip.setBufferSize(AudioTrack.getMinBufferSize(48000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT) / 2);
		}

		cpuWakelock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "telegram-voip");
		cpuWakelock.acquire();

		btAdapter=am.isBluetoothScoAvailableOffCall() ? BluetoothAdapter.getDefaultAdapter() : null;

		IntentFilter filter = new IntentFilter();
		filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
		if(!USE_CONNECTION_SERVICE){
			filter.addAction(ACTION_HEADSET_PLUG);
			if(btAdapter!=null){
				filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
				filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
			}
			filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
		}
		registerReceiver(receiver, filter);

		soundPool = new SoundPool(1, AudioManager.STREAM_VOICE_CALL, 0);
		spConnectingId = soundPool.load(this, R.raw.voip_connecting, 1);
		spRingbackID = soundPool.load(this, R.raw.voip_ringback, 1);
		spFailedID = soundPool.load(this, R.raw.voip_failed, 1);
		spEndId = soundPool.load(this, R.raw.voip_end, 1);
		spBusyId = soundPool.load(this, R.raw.voip_busy, 1);

		am.registerMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class));

		if(!USE_CONNECTION_SERVICE && btAdapter!=null && btAdapter.isEnabled()){
			int headsetState=btAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
			updateBluetoothHeadsetState(headsetState==BluetoothProfile.STATE_CONNECTED);
			//if(headsetState==BluetoothProfile.STATE_CONNECTED)
			//	am.setBluetoothScoOn(true);
			for (StateListener l : stateListeners)
				l.onAudioSettingsChanged();
		}
	} catch (Exception x) {
		if (BuildVars.LOGS_ENABLED) {
			FileLog.e("error initializing voip controller", x);
		}
		callFailed();
	}
}
 
Example 7
Source File: VoIPBaseService.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onCreate() {
	super.onCreate();
	if (BuildVars.LOGS_ENABLED) {
		FileLog.d("=============== VoIPService STARTING ===============");
	}
	try {
		AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER)!=null) {
			int outFramesPerBuffer = Integer.parseInt(am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER));
			TgVoip.setBufferSize(outFramesPerBuffer);
		} else {
			TgVoip.setBufferSize(AudioTrack.getMinBufferSize(48000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT) / 2);
		}

		cpuWakelock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "telegram-voip");
		cpuWakelock.acquire();

		btAdapter=am.isBluetoothScoAvailableOffCall() ? BluetoothAdapter.getDefaultAdapter() : null;

		IntentFilter filter = new IntentFilter();
		filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
		if(!USE_CONNECTION_SERVICE){
			filter.addAction(ACTION_HEADSET_PLUG);
			if(btAdapter!=null){
				filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
				filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
			}
			filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
		}
		registerReceiver(receiver, filter);

		soundPool = new SoundPool(1, AudioManager.STREAM_VOICE_CALL, 0);
		spConnectingId = soundPool.load(this, R.raw.voip_connecting, 1);
		spRingbackID = soundPool.load(this, R.raw.voip_ringback, 1);
		spFailedID = soundPool.load(this, R.raw.voip_failed, 1);
		spEndId = soundPool.load(this, R.raw.voip_end, 1);
		spBusyId = soundPool.load(this, R.raw.voip_busy, 1);

		am.registerMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class));

		if(!USE_CONNECTION_SERVICE && btAdapter!=null && btAdapter.isEnabled()){
			int headsetState=btAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
			updateBluetoothHeadsetState(headsetState==BluetoothProfile.STATE_CONNECTED);
			//if(headsetState==BluetoothProfile.STATE_CONNECTED)
			//	am.setBluetoothScoOn(true);
			for (StateListener l : stateListeners)
				l.onAudioSettingsChanged();
		}
	} catch (Exception x) {
		if (BuildVars.LOGS_ENABLED) {
			FileLog.e("error initializing voip controller", x);
		}
		callFailed();
	}
}