0

Hello everyone is there a way to check if Android phone is connected to any Bluetooth devices programmatically?

Should there be a state such as Bluetooth_state == Bluetooth_connected OR Bluetooth_state == Bluetooth_disconnected OR Bluetooth.isConnected(). The goal is to recognise if Phone's Bluetooth is connected to any device or not.

sud007
  • 5,824
  • 4
  • 56
  • 63
varun
  • 300
  • 4
  • 10
  • At least somebody suggest me something. Please. – varun Jun 05 '17 at 07:24
  • Well, at least you can check the bluetooth earphone `BluetoothProfile.STATE_CONNECTED == bluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEADSET)` ... – Rust Fisher Jun 05 '17 at 10:44

1 Answers1

3

If you only want to check that device is connected or not upon launch, try mBluetoothAdapter.getProfileConnectionState(); should work for you.

 public static boolean isBluetoothHeadsetConnected() {
 BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
 return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()
       && mBluetoothAdapter.getProfileConnectionState(BluetoothHeadset.HEADSET) == BluetoothHeadset.STATE_CONNECTED;
}//BluetoothHeadset.A2DP can also be used for Stereo media devices.

Don't forget to ask for permission in manifest as well.

<uses-permission android:name="android.permission.BLUETOOTH" />

Original Answer by @jobbert

sud007
  • 5,824
  • 4
  • 56
  • 63