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

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

xjtudll8年前 (2017-03-30)技术心得15170


问题:

.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) 没有回调过” 的相关文章

Google地图测距

Google地图测距

百度地图上有个测距功能,还是挺好用的。但百度地图有个缺点,没法看国外的东西,国外地图只显示了国家和首都,信息太匮乏了。 今天要测量欧洲两个城市的直线距离,百度不好使了,Google上默认又没有测距功能,搜了半天,找到了方法。 步骤如下: 1、在浏览器中输入http://ditu.google.cn/...

布丁软件引起的桌面闪烁

问题描述: 进入桌面后,屏幕闪烁。 查找到系统日志: 错误应用程序名称: explorer.exe,版本: 6.3.9600.18231,时间戳: 0x56b8c9f1 错误模块名称: PDZipMenu64.dll,版本: 1.4.3.11014,时间戳: 0x5da4349a 异常代码: 0xc...

error 65: access violation at 0x40021000 : no 'read' permission

error 65: access violation at 0x40021000 : no 'read' permission

经过测试发现,该办法仅仅适合STM32F103,对于STM32F107,即使这样修改,还是提示同样的error的。 我是在Win7 64bit下实验的 以下是参考资料: https://blog.csdn.net/beready/article/details/24668529 开发环境:keil...

Keil C51编译错误:address space overflow

Keil C51编译错误:address space overflow

近日在使用Keil的时候,遇到了一个问题:address space overflow。程序最初编译的时候没这问题,当我增加一段代码后,出现了这个问题。经网上搜索,发现根本原因是:data只能是RAM中的前128个,变量超过128个时会出现ADDRESS SPACE OVERFLOW。 &nb...

Android Studio升级至3.1出现AAPT2 error的解决办法

Android Studio升级至3.1出现AAPT2 error的解决办法

android studio从2.3升级到3.1.3之后,编译提示:AAPT2 error: check logs for details 网上的方法一堆,但几乎都没啥用。以下部分内容引用简书: https://www.jianshu.com/p/2a63c5710ee9 1:Android Stu...

Quartus Error: Signal "XX" drives an input pin”

问题: Quartus II编译提示:“Error: Signal "B" drives an input pin” 原因: 不该相连的节点(或PIN)连接到了一起了,有可能是被自动连接上了,删除不需要的连接即可。 还有种情况是:导线的名称跟Input...

发表评论

访客

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