Cant receive AT Commands from Bluetooth Headset

无人久伴 提交于 2019-12-10 20:22:07

问题


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

}

来源:https://stackoverflow.com/questions/56180759/cant-receive-at-commands-from-bluetooth-headset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!