android 4.3 BLE onCharacteristicWrite没有回调

zxm316733855 2014-09-11 12:54:11
问题1.我在自己程序有开一个Timer定时去readCharacteristic, 每次read可以成功,但是在此过程中再调用writeCharacteristic之后发现BLE设备没有接收到设置的数据,没有执行onCharacteristicWrite这个回调,把Timer关闭掉不执行readCharacteristic,只执行writeCharacteristic的时候,可以设置成功,也可以收到onCharacteristicWrite,请问有人遇到这种情况吗?该怎么解决,看起来read跟write不能同时进行,我单独开线程让这两种操作分开,还是会设置不成功,请高手指点下
问题2. 设备发送的notify信息我这里触发不了onCharacteristicChanged,我已经setCharacteristicNotification为true,并且把descriptor也设置了enable,还是接收不到,请问该怎么设置呢??有没有人做过BLE相关的,给留个QQ吧
...全文
8107 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
土逗甜菜 2016-10-14
  • 打赏
  • 举报
回复
引用 9 楼 chenggongdeli11 的回复:
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); List<BluetoothGattDescriptor> descriptors=characteristic.getDescriptors(); for(BluetoothGattDescriptor dp:descriptors){ dp.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(dp); } 加上这段试试看
9楼66666666
qq_35429136 2016-09-12
  • 打赏
  • 举报
回复
跪谢九楼。好人一生平安
feibafeibafeiba 2016-05-31
  • 打赏
  • 举报
回复
引用 10 楼 fuckme001 的回复:
[quote=引用 9 楼 chenggongdeli11 的回复:] public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); List<BluetoothGattDescriptor> descriptors=characteristic.getDescriptors(); for(BluetoothGattDescriptor dp:descriptors){ dp.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(dp); } 加上这段试试看
正解啊 跪谢[/quote] 我的只能接收到一次数据,是怎么回事
jiu_jie2 2016-04-05
  • 打赏
  • 举报
回复
大哥,咋样啊?兄弟也遇到这问题了,方便给解答一下吗?
只是一颗小草 2015-11-20
  • 打赏
  • 举报
回复
请问楼主解决了吗 遇到了同样的问题好几天了
fuckme001 2015-11-17
  • 打赏
  • 举报
回复
引用 9 楼 chenggongdeli11 的回复:
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); List<BluetoothGattDescriptor> descriptors=characteristic.getDescriptors(); for(BluetoothGattDescriptor dp:descriptors){ dp.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(dp); } 加上这段试试看
正解啊 跪谢
chenggongdeli11 2015-08-07
  • 打赏
  • 举报
回复
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); List<BluetoothGattDescriptor> descriptors=characteristic.getDescriptors(); for(BluetoothGattDescriptor dp:descriptors){ dp.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(dp); } 加上这段试试看
u011055410 2015-05-30
  • 打赏
  • 举报
回复
引用 5 楼 u013431677 的回复:
我也遇到了onCharacteristicChanged不触发的问题,触发的的时候延迟500 handler.postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub LogUtil.showMessage("enableNoti 通知"); mBluetoothLeService.enableNoti(); } }, 500);
没看明白,什么时候延迟500?是打开Opennotification 500毫秒后在写入数据吗? 我也是onCharacteristicChanged出发不了。onCharacteristicWrite倒是可以出发,返回的status = 0,有问题吗?
nuan12 2015-04-01
  • 打赏
  • 举报
回复
mBluetoothLeService.setCharacteristicNotification( characteristic, true);进行不了是什么问题 怎么改?急求解答,写入时 出现oncharacteristic staus=133,急求解答,非常感谢
黑豆黑豆 2015-01-15
  • 打赏
  • 举报
回复
5楼是正解亲测
flyly91 2015-01-14
  • 打赏
  • 举报
回复
我也遇到了onCharacteristicChanged不触发的问题,触发的的时候延迟500 handler.postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub LogUtil.showMessage("enableNoti 通知"); mBluetoothLeService.enableNoti(); } }, 500);
量化交易_wxl 2014-09-26
  • 打赏
  • 举报
回复
我也遇到了onCharacteristicChanged不触发的问题,奇怪了,你解决了吗?
哎,真难 2014-09-12
  • 打赏
  • 举报
回复
我没试过,只是初步感觉好像是这样的原因
zxm316733855 2014-09-11
  • 打赏
  • 举报
回复
引用 1 楼 heaimnmn 的回复:
写两个线程,第二个jion第一个
你这样试过可以吗?有没有实现的code膜拜下啊,我两个线程之间有加同步了的,这样不行吗?
哎,真难 2014-09-11
  • 打赏
  • 举报
回复
写两个线程,第二个jion第一个

80,471

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧