android 蓝牙 onServicesDiscovered 返回的BluetoothGatt中的特征未更新

移动开发 码拜 7年前 (2017-04-22) 1155次浏览
现在设备有A、B两种模式,
A模式有3个特征,
B模式有5个特征,
通过android 手机上的蓝牙,去切换这个两个模式,切换后设备会断开与手机的蓝牙连接,
问题:
在断开后重新连接后,并且discoverServices成功了,但是onServicesDiscovered 的参数BluetoothGatt gatt 中的特征却没有发生变化,假如重启蓝牙后,这个参数中的特征却变了,求高手解答?
解决方案

20

public boolean refreshDeviceCache(BluetoothGatt gatt) {
try {
BluetoothGatt localBluetoothGatt = gatt;
Method localMethod = localBluetoothGatt.getClass().getMethod(
“refresh”, new Class[0]);
if (localMethod != null) {
boolean bool = ((Boolean) localMethod.invoke(
localBluetoothGatt, new Object[0])).booleanValue();
return bool;
}
} catch (Exception localException) {
Log.e(“s”, “An exception occured while refreshing device”);
}
return false;
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明android 蓝牙 onServicesDiscovered 返回的BluetoothGatt中的特征未更新
喜欢 (0)
[1034331897@qq.com]
分享 (0)