我正在开发需要与Bluetooth LE设备通信的应用程序.
这是我用来设置CharacteristicNotification的代码
public boolean setCharacteristicNotification(
BluetoothGattCharacteristic characteristic, boolean enable) {
if(mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return false;
}
Log.v(TAG, "setCharacteristicNotification(): uuid=" + characteristic.getUuid() + " enabled=" + enable);
boolean notifications = mBluetoothGatt.setCharacteristicNotification(characteristic, enable);
if(notifications) {
Log.v(TAG, "setCharacteristicNotification(): Notifications are enabled");
}
else {
Log.w(TAG, "setCharacteristicNotification(): Notifications are not enabled for characteristic " + characteristic);