ble连接之后onServicesDiscovered 不被调用

问题:onServicesDiscovered never called while connecting to GATT Server

Something that has been really useful for me is to wait for about 600ms after the connection has been established and then start the service discovery.

项目中出现蓝牙连接上之后,始终不进onServicesDiscovered 回调,mBluetoothGatt.discoverServices()做如下延时即可

          if (newState == BluetoothProfile.STATE_CONNECTED) {
                intentAction = ACTION_GATT_CONNECTED;
                broadcastUpdate(intentAction);
                Log.i(TAG, "Connected to GATT server.");
                // Attempts to discover services after successful connection.
                //有时候发现服务不回调,需延时 https://stackoverflow.com/questions/41434555/onservicesdiscovered-never-called-while-connecting-to-gatt-server#comment70285228_41526267
                try {
                    Thread.sleep(600);
                    Log.i(TAG, "Attempting to start service discovery:"
                            + mBluetoothGatt.discoverServices());
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,457评论 0 23
  • 感恩祖先传承!感恩父母抚养我长大,给我良好的教育!感恩朋友的关怀,让我珍惜现在的友情!感恩同学的关注,让我觉得我是...
    我不叫许仲斌阅读 1,248评论 0 0
  • 昨日,梦里的你 星空下是一方天地 相遇多年,情在规避 多想你能来我这里休憩 藤蔓缠绕,风雨里的痕迹 问山石,问草木...
    三玄阅读 2,555评论 7 4
  • 远远的看着 远吗?我觉得很近啊, 只是看着就好开心啊
    零桶阅读 780评论 0 0
  • 654
    红昔昔阅读 819评论 0 2