的Andr​​oid如何阅读BLE属性可读可写呈报关贸总协定特点关贸总协定、属性、可读、特点

2023-09-06 03:44:09 作者:时间的尘埃

如何阅读 BluetoothGattCharacteristic 属性,如为特征可写呈报

解决方案

  / **
     * @返回返回< B>真< / B>如果属性是可写的
     * /
    公共静态布尔isCharacteristicWriteable(BluetoothGattCharacteristic PCHAR){
        返回(pChar.getProperties()及(BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE))!= 0;
    }

    / **
     * @返回返回< B>真< / B>如果属性是可读
     * /
    公共静态布尔isCharacterisitcReadable(BluetoothGattCharacteristic PCHAR){
        返回((pChar.getProperties()及!BluetoothGattCharacteristic.PROPERTY_READ)= 0);
    }

    / **
     * @返回返回< B>真< / B>如果属性是支持的通知
     * /
    公共布尔isCharacterisiticNotifiable(BluetoothGattCharacteristic PCHAR){
        返回(pChar.getProperties()及BluetoothGattCharacteristic.PROPERTY_NOTIFY)!= 0;
    }
 

How to read BluetoothGattCharacteristic properties like is characteristic Readable, Writable or Notifiable.

解决方案

    /**
     * @return Returns <b>true</b> if property is writable
     */
    public static boolean isCharacteristicWriteable(BluetoothGattCharacteristic pChar) {
        return (pChar.getProperties() & (BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE)) != 0;
    }

    /**
     * @return Returns <b>true</b> if property is Readable
     */
    public static boolean isCharacterisitcReadable(BluetoothGattCharacteristic pChar) {
        return ((pChar.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) != 0);
    }

    /**
     * @return Returns <b>true</b> if property is supports notification
     */
    public boolean isCharacterisiticNotifiable(BluetoothGattCharacteristic pChar) {
        return (pChar.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0;
    }