2017-06-02 83 views

回答

0

爲此,你必須聽取特徵變化。當您按下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); 
      }