android check if a bluetooth headset is connected

www.laut‮rut‬i.com
android check if a bluetooth headset is connected
// Check if a bluetooth device is connected in Android

fun isBluetoothHeadsetConnected(): Boolean {
    val mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
    return (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled
        && mBluetoothAdapter.getProfileConnectionState(BluetoothHeadset.HEADSET) == BluetoothHeadset.STATE_CONNECTED)
}
Created Time:2017-09-04 20:40:18  Author:lautturi