000000000000000000000
000000000000000000000

Reputation: 1467

Android check if Bluetooth connected

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();

Upvotes: 1

Views: 4997

Answers (2)

Crispert
Crispert

Reputation: 1167

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;
            }
        }
    }

Upvotes: 1

000000000000000000000
000000000000000000000

Reputation: 1467

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)

Upvotes: 0

Related Questions