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

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

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


问题:

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

金蝶K3设置套打ActiveX 部件不能创建对象

金蝶K3设置套打ActiveX 部件不能创建对象

处理方式: 打开CMD命令提示符,执行以下命令注册加载该程序集即可解决。 C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe "C:\Program Files (x86)\Kingdee\K3ERP\K3Exc...

金蝶 老单增加工具栏按钮(Raise Event)

Public Sub AddToolButton(name As String, Caption As String, Description As String, Optional imagefilename As String = '', Optional iOrder As Long = 47...

Xcode5 Version与Build设置

Xcode5 Version与Build设置

在ios中,有两种version,一种是 CFBundleVersion ("Bundle Version"),也就是我们看到的Version,另一种是CFBundleShortVersionString ("Bundle version string, short&q...

Windows Server 2012 发布RemoteApp程序

Windows Server 2012 发布RemoteApp程序

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

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

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

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

Android error:Duplicate ID, tag null, or parent id with another fragment(fragment嵌套问题)

参考资料:http://stackoverflow.com/questions/14083950/duplicate-id-tag-null-or-parent-id-with-another-fragment-for-com-google-androi 跟参考资料里的这个人一样,我也碰到了这个...

发表评论

访客

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