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);
}
}