Nic*_*hek 5 android bluetooth bluetooth-lowenergy gatt
我通过以下方式连接到ble设备:
mBluetoothGatt = device.connectGatt(this.context, false, mGattCallback);
Run Code Online (Sandbox Code Playgroud)
然后
mBluetoothGatt.disconnect();
Run Code Online (Sandbox Code Playgroud)
但如果我赶快做,然后我收到status=BluetoothGatt.GATT_FAILURE的onConnectionStateChange的mGattCallback
即使关闭/打开蓝牙,我也无法再次连接到GATT.
只有强制停止应用程序才能解决问题
mBluetoothGatt.close();通过在状态为时添加来修复STATE_DISCONNECTED
private final BluetoothGattCallback mGattCallback =
new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status,int newState) {
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
} else if (status==133&&newState == BluetoothProfile.STATE_DISCONNECTED) {
mBluetoothGatt.close();
}else if (status==BluetoothGatt.GATT_FAILURE&&newState == BluetoothProfile.STATE_DISCONNECTED){
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
mBluetoothGatt.close();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2576 次 |
| 最近记录: |