AMing* 2019-05-27 10:39
浏览 974

蓝牙Ble通知回调发送命令之后没反应,onCharacteristicChanged

在发送命令之后,onCharacteristicChanged这个回调里面接收不到数据

打开通知

 /*打开广播通知*/
    private void notifyData() {
        BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(N_Notify).getCharacteristic(uNotify);
        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        bluetoothGatt.writeDescriptor(descriptor);
        bluetoothGatt.setCharacteristicNotification(characteristic, true);
                }

发送数据

    public void writeData() {
        if (bluetoothGatt == null) {
            return;
        }
        BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(N_Write).getCharacteristic(uWrite);
        characteristic.setValue("EF52FFFAFFFF");
        bluetoothGatt.writeCharacteristic(characteristic);
    }

接收通知

     @Override
        public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
            super.onCharacteristicChanged(gatt, characteristic);
            bluetoothGatt = gatt;
            byte[] value = characteristic.getValue();
            try {
                String s=new String(value,"UTF-8");
                Log.e(TAG, "onCharacteristicChanged: "+s);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

            printNotify(value);
        }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题
    • ¥15 Python时间序列如何拟合疏系数模型