美文网首页
ble连接之后onServicesDiscovered 不被调用

ble连接之后onServicesDiscovered 不被调用

作者: 程序员学园 | 来源:发表于2017-08-16 21:12 被阅读0次

    问题: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();
                    }
                }
    

    相关文章

      网友评论

          本文标题:ble连接之后onServicesDiscovered 不被调用

          本文链接:https://www.haomeiwen.com/subject/ycxwrxtx.html