How to read BluetoothGattCharacteristic
properties like is characteristic Readable
, Writable
or Notifiable
.
The GATT profile is a general specification for sending and receiving short pieces of data known as "attributes" over a BLE link. All current BLE application profiles are based on GATT.
To find BLE devices, you use the startScan() method. This method takes a ScanCallback as a parameter. You must implement this callback, because that is how scan results are returned.
Create a new project Open Android Studio and you should be greeted with the following screen. Select Import an Android code sample. On the next screen select the sample Bluetooth Le Gatt under Connectivity. This project will set us up with a framework to build off of for our application.
A GATT service is a collection of characteristics. For example, the heart rate service contains a heart rate measurement characteristic and a body location characteristic, among others. Multiple services can be grouped together to form a profile.
/**
* @return Returns <b>true</b> if property is writable
*/
public static boolean isCharacteristicWritable(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 isCharacteristicReadable(BluetoothGattCharacteristic pChar) {
return ((pChar.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) != 0);
}
/**
* @return Returns <b>true</b> if property is supports notification
*/
public boolean isCharacteristicNotifiable(BluetoothGattCharacteristic pChar) {
return (pChar.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With