【发布时间】:2018-07-16 15:05:52
【问题描述】:
当我从参数中禁用蓝牙时遇到问题。
我使用广播接收器来监听这个动作,当它的状态关闭时,我调用一个方法来断开我的外围设备。
在我的日志中,我只看到D/BluetoothGatt: cancelOpen(),但根据BluetoothGatt.class,该服务在disconnect 方法中调用我们的BluetoothGattCallback,onConnectionStateChanged 变为DEVICE_DISCONNECTED,20 或30 秒后我也一无所有(主管超时) .
当我想直接用我的内部方法断开我的设备时,它可以正常工作。
这是断开连接的方法:
/**
* Disconnects an established connection, or cancels a connection attempt
* currently in progress.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*/
public void disconnect() {
if (DBG) Log.d(TAG, "cancelOpen() - device: " + mDevice.getAddress());
if (mService == null || mClientIf == 0) return;
try {
mService.clientDisconnect(mClientIf, mDevice.getAddress());
} catch (RemoteException e) {
Log.e(TAG,"",e);
}
}
我用反射检查了 mClientIf 是否等于 0 或者 mService 是否为 Null,但他进入下一步并输入 try/catch。所以我不明白这里的Android行为
【问题讨论】: