当我在参数中禁用蓝牙时,我遇到了一个问题。我使用广播接收器来监听这个动作,当它的状态关闭时,我调用一个方法来断开我的外围设备。在我的日志中,我只看到了D/BluetoothGatt: cancelOpen()
,但是根据BluetoothGatt.class
的说法,这个服务在disconnect
方法中调用我们的BluetoothGattCallback
,带有onConnectionStateChanged
的方法变成了DEVICE_DISCONNECTED
,在20或30秒之后我也什么都没有了(管理程序超时)。
当我想要用我的内部方法直接断开我的设备时,它可以正常工作。
这是disconnect方法:
/**
* 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是否为空,但他进入下一步并进入try/catch。所以我不理解这里的Android行为
https://stackoverflow.com/questions/51364891
复制相似问题