How to check if bluetooth is enabled programmatically?

后端 未结 6 1112
小蘑菇
小蘑菇 2020-12-13 23:46

I would like to check if bluetooth is enabled on any Android device periodically. Is there any intents that I could catch using BroadcastReceiver to do so, or is there other

6条回答
  •  情话喂你
    2020-12-14 00:06

    use can use

    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    

    for check bt connected

    mBluetoothAdapter.getProfileConnectionState(BluetoothHeadset.HEADSET) == BluetoothHeadset.STATE_CONNECTED
    

    for check bt disconnected

    mBluetoothAdapter.getProfileConnectionState(BluetoothHeadset.HEADSET) == BluetoothHeadset.STATE_DISCONNECTED
    

提交回复
热议问题