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

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

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


问题:

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

Quartus II Warning: Found 6 node(s) in clock paths which may be acting as ripple and/or gated clocks

Quartus II编译某代码之后,老是提示如下warning: Warning: Found 6 node(s) in clock paths which may be acting as ripple and/or gated clocks -- node(s) analyzed as buf...

Keil查看编译后的汇编代码

Keil查看编译后的汇编代码

在使用Keil编译C51时,一般情况下,大家都不去看汇编代码。但在某些特殊情况下,查看汇编代码就是有必要了。 (1)确认C代码是否正确 (2)研究算法 查看汇编代码前的某些准备工作是必须的:你得有工程,并确定程序编译无误。在查看汇编代码前,编译一次。 编译OK后,点Debug 有可能会提示你没有...

程序加载水晶报表

重点就是doc.load ReportDocument doc = new ReportDocument();         TreeEntityList sources = new TreeEntityList (); &nb...

老单单据上下查,某些字段在上下查出来的界面看不到

https://vip.kingdee.com/questions/55600564193023233/answers/55600565182629120 问题描述: 例如:将外购入库上的【保管】字段显示在序时簿界面,但是在采购发票序时簿上查外购入库单的界面看不到【保管】,查询起来不方便。 解决方案...

C# textBox框实现输入下拉列表

C# textBox框实现输入下拉列表

textBox框像百度搜索出现下拉列表的样式,如图: 重点就是要关注:AutoCompleteMode和AutoCompleteSource两种属性。 具体实现代码如下: 将此方法在frmLogin_Load事件里加载, private void bindTxt() {   ...

ios 获取应用程序的名称和版本号

.wiz-todo, .wiz-todo-img {width: 16px; height: 16px; cursor: default; padding: 0 10px 0 2px; vertical-align: -10%;-webkit-user-select: none;} .wiz-to...

发表评论

访客

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