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

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

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


问题:

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

Xcode Error:loaded some nib but the view outlet was not set解决

Xcode Error:loaded some nib but the view outlet was not set解决

当使用 initWithNibName 函数, 并使用由nib文件生成的ViewController 的view属性时候,遇到这个问题。 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException'...

vs2012 与 win7 不兼容的问题

vs2012 与 win7 不兼容的问题

问题描述:安装VS2012后,打开提示与此版本的 Windows 不兼容 如下图: 一开始以为是VS2010不能安装在Win7 64bit上,后来发现有个补丁,安装好之后,就能使用了。 Update for Microsoft Visual Studio 2012 (KB2781514) http...

MSP430 C语言的关键字扩展

1.interrupt 用于中断函数。 定义如下: 语法: interrupt void 函数名()          或者        interrupt[中断向量]void...

Android手机Google服务耗电过多

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

C# 一些基本的控件代码

c# 怎么用代码设置picturebox的大小,位置 picturebox.Location = new Point(x,y) 位置picturebox.Size = new Size(0,0);大小,Size里面的参数自己设置,前面是宽度,后面是高度 如何用C# 打开和保存BMP文件 操作如下:...

OSAL系统如何写中断服务函数

OSAL系统如何写中断服务函数

参考资料; http://bbs.21ic.com/icview-192248-1-1.html 问题: OSAL添加中断服务程序的时候编译报错 提示:Error[Pa045]: function "T4_ISR" has no prototype 但是定时器中断实验程...

发表评论

访客

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