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

The following examples show how to use android.media.AudioManager#isBluetoothA2dpOn() . 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: AssistantService.java    From AssistantBySDK with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(AudioManager audioManager) {
    if (voiceMediator.isBlueToothHeadSet()) {
        if (!voiceMediator.isSuportA2DP()) {
            if (audioManager.getMode() != AudioManager.MODE_NORMAL) {
                Log.e(TAG, "playInChannel>>setMode(AudioManager.MODE_NORMAL)");
                audioManager.setMode(AudioManager.MODE_NORMAL);
            }
            if (audioManager.isBluetoothScoOn()) {
                audioManager.setBluetoothScoOn(false);
                audioManager.stopBluetoothSco();
            }
        } else {
            if (!audioManager.isBluetoothA2dpOn()) {
                Log.e(TAG, "playInChannel>>setBluetoothA2dpOn(true)");
                audioManager.setBluetoothA2dpOn(true);
            }
        }
    }
}
 
Example 2
Source File: MediaPlayer.java    From qplayer-sdk with MIT License 6 votes vote down vote up
public int Init(Context context, String apkPath, int nFlag) {
	m_hHandler = new msgHandler();
	m_context = context;
	AudioManager am = (AudioManager)context.getSystemService(context.AUDIO_SERVICE);
	if (am != null && am.isBluetoothA2dpOn())
		m_nBTOffset = 250;
	m_strApkPath = apkPath;
	m_pObjPlayer = new WeakReference<MediaPlayer>(this);
	m_NativeContext = nativeInit(m_pObjPlayer, apkPath, nFlag);
	if (m_NativeContext == 0)
		return -1;
	if (m_NativeSurface != null)
		nativeSetView(m_NativeContext, m_NativeSurface);

	return 0;
}
 
Example 3
Source File: MediaStreamingStatus.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressLint("MissingPermission")
public synchronized boolean isAudioOutputAvailable() {
    Context context = contextWeakReference.get();
    if(context == null){ return false;}

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

    // If API level 23+ audio manager can iterate over all current devices to see if a supported
    // device is present.
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
        AudioDeviceInfo[] deviceInfos = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
        if(deviceInfos != null) {
            for (AudioDeviceInfo deviceInfo : deviceInfos) {
                if (deviceInfo != null && isSupportedAudioDevice(deviceInfo.getType())) {
                    return true;
                }
            }
        }
        return false;
    }

    //This means the SDK version is < M, and our min is 8 so this API is always available
    return audioManager.isBluetoothA2dpOn();
}
 
Example 4
Source File: AudioManagerUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 检查蓝牙 A2DP 音频外设是否已连接
 * @return {@code true} yes, {@code false} no
 */
public static boolean isBluetoothA2dpOn() {
    AudioManager audioManager = AppUtils.getAudioManager();
    if (audioManager != null) {
        try {
            return audioManager.isBluetoothA2dpOn();
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "isBluetoothA2dpOn");
        }
    }
    return false;
}
 
Example 5
Source File: Utils.java    From jellyfin-androidtv with GNU General Public License v2.0 5 votes vote down vote up
public static boolean downMixAudio() {
    AudioManager am = (AudioManager) TvApp.getApplication().getSystemService(Context.AUDIO_SERVICE);
    if (am.isBluetoothA2dpOn()) {
        Timber.i("Downmixing audio due to wired headset");
        return true;
    }

    return (DeviceUtils.isFireTv() && !DeviceUtils.is50()) || TvApp.getApplication().getUserPreferences().get(UserPreferences.Companion.getAudioBehaviour()) == AudioBehavior.DOWNMIX_TO_STEREO;
}
 
Example 6
Source File: AudioRender.java    From qplayer-sdk with MIT License 5 votes vote down vote up
public AudioRender(Context context, BasePlayer player) {
	mPlayer = player;
	mAudioTrack = null;
	
	AudioManager am = (AudioManager)context.getSystemService(context.AUDIO_SERVICE);
	if (am != null && am.isBluetoothA2dpOn())
		mOffset = 250;
	
	Log.v (TAG, "Audio Manager, offset  " + mOffset);
}
 
Example 7
Source File: ReactMsgListManager.java    From aurora-imui with MIT License 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    AudioManager audioManager = (AudioManager) mContext.getSystemService(AUDIO_SERVICE);
    try {
        if (audioManager.isBluetoothA2dpOn() || audioManager.isWiredHeadsetOn()) {
            return;
        }
        if (mAdapter.getMediaPlayer().isPlaying()) {
            float distance = event.values[0];
            if (distance >= mSensor.getMaximumRange()) {
                mAdapter.setAudioPlayByEarPhone(0);
                setScreenOn();
            } else {
                mAdapter.setAudioPlayByEarPhone(2);
                ViewHolderController.getInstance().replayVoice();
                setScreenOff();
            }
        } else {
            if (mWakeLock != null && mWakeLock.isHeld()) {
                mWakeLock.release();
                mWakeLock = null;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example 8
Source File: MessageListActivity.java    From aurora-imui with MIT License 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent event) {
    AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    try {
        if (audioManager.isBluetoothA2dpOn() || audioManager.isWiredHeadsetOn()) {
            return;
        }
        if (mAdapter.getMediaPlayer().isPlaying()) {
            float distance = event.values[0];
            if (distance >= mSensor.getMaximumRange()) {
                mAdapter.setAudioPlayByEarPhone(0);
                setScreenOn();
            } else {
                mAdapter.setAudioPlayByEarPhone(2);
                ViewHolderController.getInstance().replayVoice();
                setScreenOff();
            }
        } else {
            if (mWakeLock != null && mWakeLock.isHeld()) {
                mWakeLock.release();
                mWakeLock = null;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example 9
Source File: VOIPActivity.java    From voip_android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private boolean getHeadphoneStatus() {
    AudioManager audioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
    boolean headphone = audioManager.isWiredHeadsetOn() || audioManager.isBluetoothA2dpOn();
    return headphone;
}
 
Example 10
Source File: RNDeviceModule.java    From react-native-device-info with MIT License 4 votes vote down vote up
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean isHeadphonesConnectedSync() {
  AudioManager audioManager = (AudioManager)getReactApplicationContext().getSystemService(Context.AUDIO_SERVICE);
  return audioManager.isWiredHeadsetOn() || audioManager.isBluetoothA2dpOn();
}