关于用nexus 4 开发BLE应用过程数据写入后自动断开的问题

zhangwm1219_ zhangwm1219_ 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
目前在做android 蓝牙4.0的一个应用(开发手机为nexus 4),
nexus 4 蓝牙连接设备后 数据写入 不过1秒左右 提示断开了。
出现的现象为:因为硬件那边有个机制:要连接后写入指定数据,不然10秒后自动断开。
数据写入 是指,执行了我的写操作,但是在onCharacteristicWrite(BluetoothGattgatt,
BluetoothGattCharacteristiccharacteristic, int status)里面获取到的status=133,(应该就是写入不成功,但是硬件上面显示了我写入的数据)
写操作代码:(先获取到指定的服务,再获取到服务里面的指定特征,写入)
BluetoothGattServicemyBluetoothGattService = null;
myBluetoothGattService=gatt.getService(UUID.fromString(UUID_GET_MYSERVICE));
BluetoothGattCharacteristicmBluetoothGattCharacteristic=null;
mBluetoothGattCharacteristic=myBluetoothGattService.getCharacteristic(UUID.fromString(WRITE_UUID));
byte[]data = {0x00,(byte)0x0B,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
mBluetoothGattCharacteristic.setValue(data);
mBluetoothGatt.writeCharacteristic(mBluetoothGattCharacteristic)
现在疑惑在:究竟是什么原因导致断开的问题。是我写入方法有问题还是API有问题(不太可能)
PS:如果断开了 不断去重新连接,会连接成功,并且不会断开
...全文

相关推荐

评论 31
收藏 已收藏
分享
返回顶部
zhangwm1219_
Android 80,490 成员 91,371 内容