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

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

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


问题:

.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://www.xjtudll.cn/Exp/447/

标签: BLEAndroid
分享给朋友:

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

计划状态的mrp计划订单,不需要了如何手工关闭?

审核状态的计划订单才能手工关闭,建议审核以后进行关闭...

c# winform 查看网络图片

引用网址:https://blog.csdn.net/weixin_30462049/article/details/99170485 /// <summary>         /// ...

Altium 比较两个PCB的不同

Altium 比较两个PCB的不同

一般情况下,我们如果修改了PCB,都会标明大概修改了什么地方。但是有的时候,我们修改了PCB,却忘了标明改了什么地方,由于改动较小,过了一段时间之后,彻底忘了改了哪里。这时候要想知道改了哪里,该如何做? 首先,要说明的是,Altium本身的Compare功能是针对project自身的历史版本的(既可...

NSButton——设定背景图片Scale

NSButton——设定背景图片Scale

参考资料: http://stackoverflow.com/questions/5851923/how-to-scale-axes-independently-at-runtime-on-an-nsbutton 代码方式: NSButton *someButton; NSButtonCell...

QQ for Mac老提示密码错误

这段时间,一直在折腾黑苹果,好不容易将黑苹果装的差不多了,下了个QQ for Mac,安装什么的都很顺利,但是就是死活登陆不上。 1、检查过大小写,确认过密码,没错。在Windows下可以使用;在Mac系统中,Web QQ也可使用。 2、采用复制粘贴的方法将密码粘贴到密码框,依旧提示密码错误。...

DFC逻辑调频

DFC逻辑调频

2035机芯有个技术指标:DFC。如下图所示。 DFC,全称Digital Frequency Control,即逻辑调频。 我们知道,在所有的电子产品指标中,频率尤为重要,要想获得比较稳定的振荡,最广泛的就是使用石英振子,包括在手机和电脑里都有,石英手表更是如此,它用石英晶体的振荡来做时基,故...

发表评论

访客

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