当前位置:首页 > 技术心得 > 正文内容

Android BLE:onServicesDiscovered(BluetoothGatt gatt, int status) 没有回调过

xjtudll9年前 (2017-03-30)技术心得18910


问题:

.discoverServices()调用之后,却永远不回调onServicesDiscovered(BluetoothGatt gatt, int status)

基本代码如下:

public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {

            String intentAction;

            if (newState == BluetoothProfile.STATE_CONNECTED) {

                intentAction = ACTION_GATT_CONNECTED;

                mConnectionState = STATE_CONNECTED;

                broadcastUpdate(intentAction);

                Log.i(TAG, "Connected to GATT server.");

                // Attempts to discover services after successful connection.

                Log.i(TAG, "Attempting to start service discovery:" +

                        mBluetoothGatt.discoverServices());

            } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {

                intentAction = ACTION_GATT_DISCONNECTED;

                mConnectionState = STATE_DISCONNECTED;

                Log.i(TAG, "Disconnected from GATT server.");

                broadcastUpdate(intentAction);

            }

        }

原因:

android 提示newState == BluetoothProfile.STATE_CONNECTED

而实际上并不一定连接上了(连接成功是假象),尤其是连接一个不存在的设备。

参考资料:

http://stackoverflow.com/questions/25848764/onservicesdiscoveredbluetoothgatt-gatt-int-status-is-never-called

 

扫描二维码推送至手机访问。

版权声明:本文由鸟的天空发布,如需转载请注明出处。

本文链接:http://xjtudll.cn/Exp/447/

标签: BLEAndroid
分享给朋友:

“Android BLE:onServicesDiscovered(BluetoothGatt gatt, int status) 没有回调过” 的相关文章

Android的Service中弹出窗口解决方法

参考资料: http://www.cnblogs.com/fbsk/archive/2011/12/28/2304523.html http://blog.csdn.net/djun100/article/details/23756681 问题: 我们在使用Service时,经常会碰到这样的情况,比...

iPhone下xib转成iPad的xib

iPhone下xib转成iPad的xib

参考文献:http://blog.csdn.net/kmyhy/article/details/7715397 在Xcode 3中,将xib从iPhone版转变为iPad版,通过Create iPad Version菜单。 但在Xcode 4及Xcode5中,这个菜单找不到了。但是可以通过其...

工作台待处理业务、待处理流程、待审批、我的跟进、预警、消息对应的数据表

https://vip.kingdee.com/questions/152510144306059546/answers/152510187037628697 工作台待处理业务、待处理流程、待审批、我的跟进、预警、消息对应的数据表如下: 待处理业务:t_SuspendWorkPushMain、t_S...

Quartus II 破解器 在win7无法运行,停止工作

Quartus II 破解器 在win7无法运行,停止工作

参考资料: http://zhidao.baidu.com/link?url=6-4yMJ7njWfCK7grjNaR-EspkM9MqtpoFB5HYFa5yJK7f4sbLrMMXSd8kruGlZnmLZtP9AYQFvD70hEmR8ZV3K 现象如图所示,只要一破解,就会弹出“...

按键精灵手机助手无法连接到手机调试

现象: 按键精灵手机助手无法连接到手机调试 手机已打开开发者选项,已选择USB调试   解决办法: 打开手机上的按键精灵,此时手机助手连上了……...

监听viewcontroller进入后台

首先,要说明的是: ViewWillDisappear在进入后台的时候 不会 被触发 监听Home键进入后台: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResig...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。