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")
}
}
}