首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android DeadObjectException :writeCharacteristic、、DeadObjectException、

Android DeadObjectException :writeCharacteristic、、DeadObjectException、
EN

Stack Overflow用户
提问于 2017-03-15 11:35:13
回答 1查看 700关注 0票数 0

我扫描了蓝牙,链接并发送了启动蓝牙设备测量功能的指令,发现了以下错误:

代码语言:javascript
复制
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 

当我将蓝牙连接到我的手机时,我想要发送CMD到蓝牙设备并获取特征。我使用的方法是mBluetoothGatt.writeCharacteristic(characteristic)mBluetoothGatt.readCharacteristic(characteristic)mBluetoothGatt.setCharacteristicNotification(characteristic, enabled),It is error。myCode:

活动:

代码语言:javascript
复制
if (uuid.contains("fff3")){
    mBluetoothLeService.wirteCharacteristic(gattCharacteristic);
    mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true);
    mBluetoothLeService.readCharacteristic(gattCharacteristic);
}

服务类别为:

代码语言:javascript
复制
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);
    }
}
EN

回答 1

Stack Overflow用户

发布于 2017-03-17 21:37:43

这就是mBluetoothGatt.writeCharacteristic(characteristic).的问题特征不是设置值。

正确的代码是:

代码语言:javascript
复制
characteristic.setValue(bytes);
mBluetoothGatt.writeCharacteristic(characteristic);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42800652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档