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

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

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


问题:

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

添加 PreferenceFragment到FragmentPagerAdapter

添加 PreferenceFragment到FragmentPagerAdapter

如何添加 PreferenceFragment到FragmentPagerAdapter 首先,android v4 support library不支持这个功能,android v13 support library才支持这个功能。 如何从android v4 support library升级到...

sharepoint配置提示:(local)为无效地址或环回地址。请指定一个有效的服务器地址。”

sharepoint配置提示:(local)为无效地址或环回地址。请指定一个有效的服务器地址。”

环境: windows2008R2(x64) SQL2008R2,.NET Framework4.0 sharepoint2010(X64) 数据库服务器:“(local)”, 如图所示: 配置到最后一步时,提示: “未能创建配置数据库。 已引发类型为Syste...

Android Studio Warning:Not annotated parameter overrides @NonNull parameter

问题: android studio提示:Not annotated parameter overrides @NonNull parameter 分析: Warning:The @NonNull annotation can be used to indicate that a given par...

C# 动态加载DLL 通过反射 调用参数、方法、窗体

.net中常会用到动态加载DLL,而DLL中可能包含各种参数、方法、窗体,如何来调用动态加载这些参数、方法、窗体呢? 在C#中,我们要使用反射,首先要搞清楚以下命名空间中几个类的关系: System.Reflection命名空间 (1)   AppDomain:应用程序域,可以将...

光耦应用笔记

1、光耦的简介及分类 光耦合器(opticalcoupler,英文缩写为OC)亦称光电隔离器或光电耦合器,简称光耦。它是以光为媒介来传输电信号的器件,通常把发光器(红外线发光二极管LED)与受光器(光敏半导体管)封装在同一管壳内。当输入端加电信号时发光器发出光线,受光器接受光线之后就产生光电流,从...

如何给程序添加超大图标(EXE大尺寸图标)

如何给程序添加超大图标(EXE大尺寸图标)

要点:1、制作多分辨率ICON文件2、清空图标缓存,使图标文件生效 自己写的程序,如果更换了图标,编译出来,超大图标显示就会发现图标并没有跟着放大。那么问题来了,就换个图标效果就不同了,很明显时图标有问题。用eXeScope打开vs2013编译出来的MFC对话框程序可以看到如下图:这不止一...

发表评论

访客

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