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

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

xjtudll10年前 (2017-03-30)技术心得19540


问题:

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

BLE 128位UUID规定及使用

BLE 128位UUID规定及使用

参考资料: http://www.deyisupport.com/question_answer/wireless_connectivity/f/45/t/30862.aspx 问题: 私有profile必须要用128位的UUID? 答案: 16bit UUID是SIG定义的,私有profile需...

CodeBlocks安装error:can't find compiler executable in your ...

CodeBlocks安装error:can't find compiler executable in your ...

参考资料:http://blog.sina.com.cn/s/blog_5fea94370102vait.html 问题描述: 第一次安装CodeBlocks,安装到了D盘,非默认目录。打开过软件。后来操作失误,卸载了。 第二次安装CodeBlocks,安装在了默认盘C盘,安装后再次打开,提示找不到...

VS2010 HelpLibrary

VS2010 HelpLibrary

1、VS2010 HelpLibrary路径更改 找到helplibmanager.exe.config (C:\Program Files\Microsoft Help Viewer\v1.0\),打开 helplibmanager.exe.config (用记事本或其他文本编辑软件),将 key...

Android 6.0:收不到BluetoothDevice.ACTION_FOUND广播

Android 6.0:收不到BluetoothDevice.ACTION_FOUND广播

参考资料: http://stackoverflow.com/questions/32656510/register-broadcast-receiver-dynamically-does-not-work-bluetoothdevice-action-f https://developer.and...

IAR Fatal Error[Cp001]解决

IAR Fatal Error[Cp001]解决

很久没用IAR了,这次重新折腾MSP430,安装软件后,编译程序,提示一个莫名奇妙的错误,以前一直没碰到过,错误内容如下: Fatal Error[Cp001]: Copy protection check, No valid license found for this product [20]...

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

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

发表评论

访客

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