【发布时间】:2016-07-29 16:26:05
【问题描述】:
我正在尝试使用 BLE 模块在 android 设备和自定义板之间交换数据。而且我在 Android 设备 5.0 及更高版本上的特性写()方法有一些问题。在情人版本中,characteristicsWrite() 方法返回 true,然后在 BleGattCallback 中调用 onCharacteristicsWrite() 回调
写法:
private void sendMessageToDevice(String message) {
byte nullByte = 0x00;
byte[] temp = message.getBytes();
byte[] tx = new byte[temp.length + 1];
tx[tx.length - 1] = nullByte;
System.arraycopy(temp, 0, tx, 0, temp.length);
characteristicWrite.setValue(tx);
boolean writeResult = mBluetoothGatt.writeCharacteristic(characteristicWrite);
Log.d(LOG_TAG, "writeResult"); //true
}
onCharacteristicsWrite 方法:
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
super.onCharacteristicWrite(gatt, characteristic, status);
Log.d(LOG_TAG, status); // status = 0 - GATT_SUCCESS
}
但是当我在 android 设备 v 5.0 上执行此代码时 writeCharacteristic() 方法的结果始终为 false,并且未调用 onCharacteristicWrite() 回调。
谁能解释一下如何在 BLE 设备和 Android 5.0+ 之间正确建立连接?也许我需要一些针对这种设备的特定方法。 在三星和联想智能手机 v5.0+ 上测试的应用程序。
【问题讨论】:
-
你确定你的
GATT层连接正确吗? -
应用程序在 5.0 版本以下的 android 设备上运行良好,所以我猜层连接正确。我正在使用这个教程来创建连接:Android BLE
标签: java android callback bluetooth-lowenergy gatt