When does android.bluetooth.headset.action.VENDOR_SPECIFIC_HEADSET_EVENT get triggered?-ThrowExceptions

Exception or error:

In my application, I want to get the battery information from a bluetooth headset. I have read that “android.bluetooth.headset.action.VENDOR_SPECIFIC_HEADSET_EVENT” broadcasts sensor information from
which battery info can be obtained.

I have added the necessary actions and categories.

 private fun registerForBluetoothChanges(context: Context) {
    val bluetoothIntentFilter = IntentFilter()
    bluetoothIntentFilter.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY + "." + BluetoothAssignedNumbers.PLANTRONICS)

    bluetoothIntentFilter.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY + "." + BluetoothAssignedNumbers.SAMSUNG_ELECTRONICS
    )
    bluetoothIntentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
    bluetoothIntentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
    bluetoothIntentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED);
    bluetoothIntentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
    bluetoothIntentFilter.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT);
    bluetoothIntentFilter.addAction(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
    bluetoothIntentFilter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
    BluetoothListener.registerReceiver(context.applicationContext, bluetoothIntentFilter)
}

I have also declared bluetooth permission in the manifest.
My queries are :

  1. Can the above broadcast be used to listen for battery changes? If so, when will the event be triggered?
  2. The broadcast event was never received. Tried with Samsung level U headphones on Moto G6(Android 9) and Samsung Tab A(Android 8.1). Is there anything which I’m missing here?
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *