关于用nexus 4 开发BLE应用过程数据写入后自动断开的问题
目前在做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:如果断开了 不断去重新连接,会连接成功,并且不会断开