3

I am trying to receive AT command broadcast from a Bluetooth headset ( samsung made) , it connects just fine , but code below isn't giving anything , what is that I am missing here ? I am basically trying to get battery level of headset

Any pointers will be a great help.

This is how I am registering the receiver.

    val intentFilter = IntentFilter()
    intentFilter.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT)
    intentFilter.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY + '.'.toString() + BluetoothAssignedNumbers.SAMSUNG_ELECTRONICS)
    registerReceiver(receiver, intentFilter)

The broadcast receiver looks like this

  private val receiver = object : BroadcastReceiver() {

    override fun onReceive(context: Context, intent: Intent) {
        val action = intent.action
        Log.d("COMMAND", "onReceive: " + action!!)
        if (action == BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT) {
            //not working
            val command = intent.getStringExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD)
            val type = intent.getIntExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE, -1)
            Log.d("COMMAND", "onReceive: $command type: $type")
        }
    }

}
vishal dharankar
  • 7,536
  • 7
  • 57
  • 93
  • Have you had any success with this? The Google docs reference Plantronics as an example manufacturer with the `BluetoothAssignedNumbers` https://developer.android.com/reference/android/bluetooth/BluetoothHeadset#ACTION_VENDOR_SPECIFIC_HEADSET_EVENT -I have this working without issue. I have tried, using exact same procedure, Samsung/Sennheiser & Jabra (Gn Netcom) bluetooth headsets (using correct `BluetoothAssignedNumbers` id's). None of these work at all, thanks Google! The public api for `BluetoothHeadset` is very restrictive and offers no callbacks for events without modifications at AOSP – Mark May 26 '19 at 21:05
  • Would you mind sharing the example ? – vishal dharankar May 27 '19 at 03:40
  • The example is almost identical to yours (apart from using `BluetoothAssignedNumbers.PLANTRONICS` and other manufacturer numbers). There is no completed setup - just an intent filter and receiver. The example I looked for plantronics was here : https://developer.plantronics.com/article/plugging-plantronics-headset-sensor-events-android however take away the custom code and it is still just using same `BroadcastReceiver` setup as well. I will be delving into the AOSP source code, so will update if I find something. – Mark May 27 '19 at 10:32
  • Ok I got that however is there any need to send an AT command to trigger that broadcast ? May be in some cases ? Or not required at all ? Should it work itself ? – vishal dharankar May 27 '19 at 17:19

0 Answers0