0
我正在使用BLE device.I執行代碼使用android GATT和它掃描設備,我也發送立即警報BLE設備從移動使用writeCharacteristic和BLE設備蜂鳴。但現在我當我按下BLE設備按鈕時,要在android mobile中提醒。那正是我不知道該怎麼做的。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);
}