Android BLE设备按钮在Android中的按钮警告
问题描述:
我正在使用BLE device.I执行代码使用android GATT和它扫描设备,我也发送立即警报BLE设备从移动使用writeCharacteristic和BLE设备蜂鸣。但现在我当我按下BLE设备按钮时,要在android mobile中提醒。那正是我不知道该怎么做的。Android BLE设备按钮在Android中的按钮警告
谢谢。
答
为此,你必须听取特征变化。当您按下BLE按钮时,必须在硬件内部更改特性(设置任何标志值取决于硬件的固件编码)。当特征发生变化时,将调用特征方法。您可以在那里执行所需的功能。
@Override
public void onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic
characteristic)
{
Here we received ble button pressed event callback. Do stuff here.
}
对于接收特性首先更改回调,您必须启用这样的通知。
BluetoothGattCharacteristic characteristic = gatt.getService(mServiceUuuid).getCharacteristic(mCharOneUuuid);
gatt.setCharacteristicNotification(characteristic, true);
List<BluetoothGattDescriptor> list = characteristic.getDescriptors();
for (int i = 0; i < list.size(); i++) {
BluetoothGattDescriptor desc = list.get(i);
desc.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gatt.writeDescriptor(desc);
}