0

When my code didn't work, I started with the project I found here and ran it against our custom bluetooth device on my moto-x. Against the general attributes with profiles, I get data back from the following code:

public void readCharacteristic(BluetoothGattCharacteristic characteristic) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }
    mBluetoothGatt.readCharacteristic(characteristic);
}

which returns data asynchronously in:

    public void onCharacteristicRead(BluetoothGatt gatt,
                                     BluetoothGattCharacteristic characteristic,
                                     int status) {
        if (status == BluetoothGatt.GATT_SUCCESS) {
            broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
        }
    }

This also works if i run this code against a heart rate monitor.

If I run it against one of our custom properties without a default profile, the data never comes back. Ever.

A google search included this: Cannot read characteristic. Android BLE but setting up notifications did not solve my problem.

Any advice?

Community
  • 1
  • 1
Thom
  • 14,013
  • 25
  • 105
  • 185

1 Answers1

0

I think the PROPERTY_READ, PROPERTY_WRITE isn't set to enabled in your custom properties.

Check for BluetoothGattCharacteristic PROPERTIES -I didn't realize that need to enable the PROPERTY_WRITE, PROPERTY_READ on the BLE hardware and that wasted a lot of time.

The part where to check the PROPERTY should be something like:

if ((characteristic.getProperties() && 
BluetoothGattCharacteristic.PROPERTY_READ)> 0) {
     // toast or log here
      }

These enable/disable the app or for that matter any app to connect to the bluetooth low energy device

Refer servicesListClickListner on this page

Pararth
  • 8,114
  • 4
  • 34
  • 51