【发布时间】:2020-12-24 17:00:44
【问题描述】:
我正在尝试在我的 Android 手机和我的设备之间建立联系。在他们通过我的gattCallback 调用device.connectGatt() 连接之前。但是现在我还想通过调用device.createBond() 添加绑定,我的onConnectionStateChange 显示连接和断开的交替模式,连接时状态码为0,断开时状态码为8。这是我尝试将connectGatt 和createBond 一起使用的代码的sn-p。
@Override
public void onScanResult(int callbackType, ScanResult result) {
System.out.println("on scan result");
super.onScanResult(callbackType, result);
BluetoothDevice device = result.getDevice();
synchronized (this) {
if (mBluetoothGatt == null) {
if (device.createBond()) {
System.out.println("create bond success");
mBluetoothGatt = device.connectGatt(mListener.retrieveApplicationContext(), true, mGattCallback);
}
else System.out.println("create bond sb");
}
}
}
这样调用这两个方法有什么问题吗?我在互联网上搜索了创建债券,但没有一个页面同时使用 createBond 和 connectGatt。我只是从这篇文章中得到了关于如何以这种方式调用这两种方法的提示:Android BLE onCharacteristicChanged() using notify not triggered
另外,我的BroadCastReceiver 也总是显示设备绑定,但从不显示设备绑定。
【问题讨论】:
标签: android bluetooth-lowenergy nrf51