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

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

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


问题:

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

c# toolstrip控件怎么把左边的几个小点去掉

c# toolstrip控件怎么把左边的几个小点去掉

c# toolstrip控件怎么把左边的几个小点去掉 小点如下图所示: 解决办法: 选中你的toolstrip 然后属性 属性中有个 GripStyle 设置Hidden...

Protel99SE PCB各层的含义

本文收集于网络,整理而成,原文作者未知。 我们在进行印制电路板设计前,第一步就是要选择适用的工作层。Protel 99 SE提供有多种类型的工作层。只有在了解了这些工作层的功能之后,才能准确、可靠地进行印制电路板的设计。 Protel 99 SE所提供的工作层大致可以分为7类:Signal La...

解决android studio弹出

解决android studio弹出"waiting for debugger"

方式一: 这种方法可能需要配置环境变量 win+R -> cmd -> adb kill-server,adb start-server 方式二: 当点击debug app时(卡在"waiting for debug"),则如图点击,然后点击确定即可! 本文为转载...

C# XmlSerializer无法创建文件或目录

C# XmlSerializer无法创建文件或目录

现象: 在某一台XP机器上,时而正常,时而弹出无法创建文件或目录 错误具体信息: 在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 在 System.IO.FileStream.Init(String path...

线反转法行列键盘扫描

线反转法行列键盘扫描

    行列键盘的学习是单片机学习的必经之路,可是对于初学者来说学习起来并不容易。书上的资料不多,或是说明不细,亦或太复杂不易理解。而线反转法行列键盘扫描简单易懂,非常适合初学者学习,也可作为程序开发之用。    了解行...

Windows Server 2012 发布RemoteApp程序

Windows Server 2012 发布RemoteApp程序

https://blog.51cto.com/vic366/924410 打开管理器管理器仪表板,选择本地服务器->远程桌面服务 选择集合->QuickSessionCollection->任务->发布RemoteApp程序 选择要发布程序的程序 如果程序不在列表中,可以...

发表评论

访客

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