Android How to read BLE properties Readable Writable Notifiable GATT Characteristics

前端 未结 2 1535
春和景丽
春和景丽 2021-02-14 02:09

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

2条回答
  •  天涯浪人
    2021-02-14 03:07

        /**
         * @return Returns true if property is writable
         */
        public static boolean isCharacteristicWritable(BluetoothGattCharacteristic pChar) {
            return (pChar.getProperties() & (BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE)) != 0;
        }
    
        /**
         * @return Returns true if property is Readable
         */
        public static boolean isCharacteristicReadable(BluetoothGattCharacteristic pChar) {
            return ((pChar.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) != 0);
        }
    
        /**
         * @return Returns true if property is supports notification
         */
        public boolean isCharacteristicNotifiable(BluetoothGattCharacteristic pChar) {
            return (pChar.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0;
        }
    

提交回复
热议问题