我需要从fff2特征中获取价值。 其特征仅返回01或00
如何获得价值?
this是我想要的示例值。
public boolean readCharacteristic(){
//check mBluetoothGatt is available
if (bluetoothGatt == null) {
Log.e(TAG, "lost connection");
return false;
}
BluetoothGattService Service = bluetoothGatt.getService(UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb"));
if (Service == null) {
Log.e(TAG, "service not found!");
return false;
}
BluetoothGattCharacteristic charac = Service
.getCharacteristic(UUID.fromString("0000fff2-0000-1000-8000-00805f9b34fb"));
if (charac == null) {
Log.e(TAG, "char not found!");
return false;
}
final byte[] data = charac.getValue(); // return null
String s2 = new String(data);
Log.i("READ", s2);
boolean status = true;
return status;
}
感谢..
答案 0 :(得分:0)
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
byte[] data = characteristic.getValue();
}
}
如果需要,将字节数组转换为十六进制格式。 希望这有用。