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

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

xjtudll7年前 (2017-03-30)技术心得12920


问题:

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

Altium Designer:将Sch.Lib和Pcb.Lib库文件整合成.intlib库文件

Altium Designer:将Sch.Lib和Pcb.Lib库文件整合成.intlib库文件

参考资料: http://www.51hei.com/bbs/dpj-39220-1.html 每个.intlib (integrated library) 需包含 .pcblib (建封装) 和 .schlib (路线图) 两个文件。 (1) 创建 .intlib (file ->...

ReportViewer(RDLC报表)打印很多空白页

ReportViewer(RDLC报表)打印很多空白页

问题: RDLC报表打印的时候,会多出空白页。 一页有内容,一页空白。然后有内容,然后继续空白。交替出现空白。 原因: 报表的宽度+左边距+右边距 > 纸张宽度 参考资料: https://blog.csdn.net/u012293369/article/details/78885091 解决...

Android手机Google服务耗电过多

手机:三星I9000 操作系统:Android 2.3.3 (Lida ROM) 现象:电池使用时间很短,经常莫名其妙就没电了。查看电量消耗,60%(甚至更多)为“Google框架服务”占用。 病因: 通过网络搜索,发现是因为曾经禁止了“Google框架服务&rd...

物料新增工艺路线后是否会更新到物料计划资料中的工艺路线?

https://vip.kingdee.com/questions/141197/answers/166759 解决方案: 【概述】 当工艺路线新增时,选择缺省状态是“是”时,工艺路线审核以后会自动更新到物料的工艺路线。...

位运算——交换两个数

交换两个数 交换两个数相信很多人天天写过,我也相信你每次都会使用一个额外来变量来辅助交换,例如,我们要交换 x 与 y 值,传统代码如下 int tmp = x; x = y; y = tmp; 这样写有问题吗?没问题,通俗易懂,万一哪天有人要为难你,**不允许...

自定义"back" navigation button 的动作

目的: 监测“返回”按键,并执行相关操作。 问题分析: 首先,“返回”按键是无法监测的,但是返回操作后,界面上会有所改变,所以可以在VIewWillDisappear中执行相关操作。   参考资料: http://stackoverflow...

发表评论

访客

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