1

I am searching for this on the internet for quite a while, but I can't find what I am looking for.

How can I find out with my app, if my device is already connected to a Bluetooth device (/ was before I start my app).

I was hoping there was something like bool BluetoothAdapter.isPaired();

Yogesh
  • 1,565
  • 1
  • 19
  • 46
000000000000000000000
  • 1,467
  • 1
  • 19
  • 38
  • Possible duplicate of [How to programmatically tell if a Bluetooth device is connected? (Android 2.2)](http://stackoverflow.com/questions/4715865/how-to-programmatically-tell-if-a-bluetooth-device-is-connected-android-2-2) – Strider Jun 27 '16 at 09:44
  • @Strider OK - thx. So it's basically impossible. :( – 000000000000000000000 Jun 27 '16 at 09:58
  • 1
    Duplicate question : check this answer here, : http://stackoverflow.com/a/4716715/5476209 – TapanHP Jun 27 '16 at 10:08

2 Answers2

1

If you are only interested if a connection to an arbitrary bluetooth device is established you can use the BluetoothAdapter.getProfileConnectionState(profile):

    adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null && adapter.isEnabled()) {
        int[] profiles = {BluetoothProfile.A2DP, BluetoothProfile.HEADSET, BluetoothProfile.HEALTH};
        boolean connectionExists = false;
        for (int profileId : profiles) {
            if (BluetoothAdapter.getProfileConnectionState(profileId) == 
                                    BluetoothProfile.STATE_CONNECTED) {
                connectionExists = true;
                break;
            }
        }
    }
Crispert
  • 1,102
  • 7
  • 13
  • Thanks Crispert - this was really helpful thank you! It was especially helpful because it covers scenarios when devices with different `BluetoothProfile`s are connected – Tom Larcher Oct 04 '19 at 01:44
0

There is no way to retrieve a list of connected devices at application startup. The Bluetooth API does not allow you to QUERY, instead it allows you to listen to CHANGES.

(s. This question)

Community
  • 1
  • 1
000000000000000000000
  • 1,467
  • 1
  • 19
  • 38