2017-06-02 84 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); 
      }