无法从蓝牙耳机接收AT命令

时间:2019-05-17 06:28:52

标签: java android kotlin bluetooth a2dp

我正在尝试从蓝牙耳机(三星制造)接收AT命令广播,它连接得很好,但是下面的代码没有给出任何信息,我在这里缺少什么?我基本上是在尝试获取耳机的电池电量

任何指针都会有很大帮助。

这就是我注册接收者的方式。

    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)

广播接收器看起来像这样

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

}

0 个答案:

没有答案