Android bluetooth. Determine if the paired device is set to 'on'

I want to determine if the paired device is active. I really don't need to connect to it, just determine if it has a heartbeat.

I am struggling with a series of I / O errors when trying to connect a bluetooth socket, but I'm not sure what I really need.

+3
source share
2 answers

Assuming you are using Android If you have a BluetoothDevice object for this device, you can register to listen to the broadcast actions - ACL_CONNECTED or ACL_DISCONNECTED and monitor the status of the connection.

+2
source

, BT-Headset ( ), :

        <intent-filter >
            <action android:name="android.bluetooth.headset.action.AUDIO_STATE_CHANGED" />
        </intent-filter>

onReceive :

if ("android.bluetooth.headset.action.AUDIO_STATE_CHANGED".equals(intent.getAction())) {
  headsetAudioState = intent.getIntExtra("android.bluetooth.headset.extra.AUDIO_STATE", -2);
}

int . , , BT- (1)/ (0). , .

: https://github.com/android/platform_frameworks_base/blob/gingerbread/core/java/android/bluetooth/BluetoothHeadset.java

0

Source: https://habr.com/ru/post/1792315/


All Articles