【发布时间】:2017-06-04 17:50:44
【问题描述】:
我对 BLE 有点熟悉,但我在继承代码方面遇到了一些问题。所以应用程序是这样工作的:
- 启用 BLE 后,应用会扫描设备
- 应用会显示找到的设备
- 用户选择要配对的设备
- 应用与设备配对
我面临的问题是多次配对后(它会有所不同),手机无法发现设备,从而阻止用户配对。
我正在使用 GattServer 连接客户端设备,我正在重置服务,如下所示:
public void resetBluetoothGattServer() {
Log.i(TAG," resetBluetoothGattServer: bluetoothGattServer: "+ bluetoothGattServer);
if (bluetoothGattServer != null) {
if(!bluetoothGattServer.getServices().isEmpty()){
Log.i(TAG," resetBluetoothGattServer: clearing services on bluetooth Gatt Server");
bluetoothGattServer.clearServices();
}
Log.i(TAG," resetBluetoothGattServer: closing bluetoothGattServer");
bluetoothGattServer.close();
}
bluetoothGattServer = openGattServer();
}
重启手机、关闭蓝牙再打开、卸载再安装应用程序都无法解决问题。唯一的解决办法是从安卓应用管理器上的蓝牙共享应用清除缓存。
这篇帖子How to programmatically force bluetooth low energy service discovery on Android without using cache 解决了一个类似的问题,但由于我们没有使用 BluetoothGatt 进行连接,所以它不是一个合适的解决方案。两者都不会重构整个继承的代码。
我在问你是否有办法使用 BluetoothGattServer 以编程方式清除缓存。
【问题讨论】:
-
找到答案了吗?我面临着类似的问题。
-
@IgorGanapolsky 看起来他不在线。你找到解决办法了吗?我也有类似的问题。
-
Android 10 发布后我们也面临同样的问题。
-
@SanjayKakadiya 你找到解决方案了吗?
-
@Keselme 是的,我们修复了 BLE 连接问题。我们在连接之前扫描 BLE 设备。
标签: android bluetooth bluetooth-lowenergy clear-cache bluetooth-peripheral