0

I scanned the Bluetooth, linked and sent instructions to start the Bluetooth device's measurement function and found the following error:

03-15 11:12:44.903 22685-22685/com.homehealth.bluetooth_one E/BluetoothGatt: android.os.DeadObjectException
  at android.os.BinderProxy.transact(Native Method)
  at android.bluetooth.IBluetoothGatt$Stub$Proxy.writeCharacteristic(IBluetoothGatt.java:933)
  at android.bluetooth.BluetoothGatt.writeCharacteristic(BluetoothGatt.java:952)
  at com.homehealth.bluetooth_one.BluetoothLeService.wirteCharacteristic(BluetoothLeService.java:283)
  at 

When I connect the bluetooth with my phone, I want to send CMD to bluetooth device and getting the characteristic . I use the methods that mBluetoothGatt.writeCharacteristic(characteristic),mBluetoothGatt.readCharacteristic(characteristic),mBluetoothGatt.setCharacteristicNotification(characteristic, enabled),It is error. myCode:

Activity :

if (uuid.contains("fff3")){
    mBluetoothLeService.wirteCharacteristic(gattCharacteristic);
    mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true);
    mBluetoothLeService.readCharacteristic(gattCharacteristic);
}

Service class is :

public void wirteCharacteristic(BluetoothGattCharacteristic characteristic) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }
    boolean success = mBluetoothGatt.writeCharacteristic(characteristic);
    if (success) Log.i(TAG,"wirteCharacteristic successful");
}
public void readCharacteristic(BluetoothGattCharacteristic characteristic) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoohAdapter not initialized");
        return;
    }
    Log.i(TAG,"readCharacteristic UUID="+characteristic.getUuid().toString());
   boolean success =  mBluetoothGatt.readCharacteristic(characteristic);
    if (success) Log.i(TAG,"readCharacteristic successful");
}
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
                                          boolean enabled) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }

    boolean successful = mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
    mBluetoothGatt.writeCharacteristic(characteristic);
    if (successful) {

        Log.i(TAG,"setCharacteristicNotification successful");


        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(characteristic.getUuid());
        if (null == descriptor) {

            Log.e(TAG, "descriptor is null,or UUID is invalid  uuid=" + characteristic.getUuid());
            return;
        }
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(descriptor);
    }
}
Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
Mr.Four
  • 67
  • 10
  • Possible duplicate of [How to fix android.os.DeadObjectException android X](http://stackoverflow.com/questions/1573557/how-to-fix-android-os-deadobjectexception-android-x) – Ken Y-N Mar 15 '17 at 03:42
  • I've marked this as a duplicate, but without any code we cannot say what might be the problem, although your application stopping prematurely seems to be the most common cause. – Ken Y-N Mar 15 '17 at 03:43
  • please add the code. – siva Mar 15 '17 at 05:46
  • My codes have uploaded; – Mr.Four Mar 15 '17 at 14:55

1 Answers1

0

It is the problem that mBluetoothGatt.writeCharacteristic(characteristic). characteristic is not setting Value.

the right code is :

characteristic.setValue(bytes);
mBluetoothGatt.writeCharacteristic(characteristic);
Mr.Four
  • 67
  • 10