上图先
之前在BluetoothGattCallback.onConnectionStateChange中使用discoverServices()后BluetoothGattCallback.onServicesDiscovered不回调或部分回调,在网上搜寻到方案是在gatt.discoverServices()之前加延时也只能部分解决问题,当时估计应该是线程问题。后来将涉及到UI线程的控件更新去除,无需延时完美解决。
原因大概是因为该回调不是在UI线程中运行,故在该回调中使用其它线程有可能造成BluetoothGattCallback.onServicesDiscovered不回调或部分回调。如确有需要使用诸如UI线程操作,建议在该回调中使用Handler的message等方法。