Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android How to read BLE properties Readable Writable Notifiable GATT Characteristics

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

like image 691
AZ_ Avatar asked Jan 23 '14 06:01

AZ_


People also ask

What is GATT service on Android?

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.

How do I scan my Android phone with BLE?

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.

How do Android apps communicate with custom BLE?

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.

What is GATT characteristics?

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.


1 Answers

    /**
     * @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;
    }
like image 180
AZ_ Avatar answered Oct 04 '22 10:10

AZ_