android ble连接过程中断开连接,BLE设备自动与Android设备断开连接。 Android BLE

我正在使用Android Nexus 7通过Bluetooth Low Energy链接连接设备。 我能够连接设备,并且如果我不与设备进行任何通信,则保持连接。

但是,如果我通过单击按钮启用一个特定特征的通知,则设备将在数秒传输数据后与平板电脑断开连接。

有谁知道可能是什么问题? 非常感谢你!

这是我的代码:

public boolean setCharacteristicNotification(boolean enabled){ if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return false; } BluetoothGattService Service = mBluetoothGatt.getService(UUID_MY_SERVICE); if (Service == null) { Log.e(TAG, "service not found!"); return false; } BluetoothGattCharacteristic characteristic = Service.getCharacteristic(UUID_MY_CHARACTERISTIC); final int charaProp = characteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); BluetoothGattDescriptor descriptor = characteristic.getDescriptor( UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); return true; } return false; }

(在问题编辑中回答。转换为社区维基答案。请参阅问题答案添加到问题本身时,适当的操作是什么? )

OP写道:

我今天解决了这个问题。

只需更改descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);

到descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);

跟进:

在我做了一些研究和测试后,我发现自动断线问题与Nexus 7上的蓝牙和WIFI之间的干扰有关。如果我关闭了WIFI,那么蓝牙的断开问题已经消失。 并且这个问题在Galaxy 3,4,5上没有发生。

问题:我在Tesco Hudl 2上遇到了同样的问题,如果我在连接蓝牙后立即传输一些数据,它将断开连接。

解决方案:连接后等待几秒钟,似乎工作正常。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值