Android 如何在设置中断开蓝牙连接而不取消配对

Android 如何在设置中断开蓝牙连接而不取消配对,android,bluetooth,Android,Bluetooth,我需要一种方法来取消蓝牙连接。例如,单击设置以断开连接,但不要取消配对我解决了这个问题。我的蓝牙设备是一个输入设备,BluetoothUtil.input\u device\u PROFILE=4 private void disconnectToDevice() { if (mConnectedDevice != null) { mBluetoothAdapter.getProfileProxy(mContext, new BluetoothPr

我需要一种方法来取消蓝牙连接。例如,单击设置以断开连接,但不要取消配对

我解决了这个问题。我的蓝牙设备是一个输入设备,BluetoothUtil.input\u device\u PROFILE=4

    private void disconnectToDevice() {
        if (mConnectedDevice != null) {
            mBluetoothAdapter.getProfileProxy(mContext, new BluetoothProfile.ServiceListener() {
                @Override
                public void onServiceConnected(int profile, BluetoothProfile proxy) {
                    LogUtil.d("getProfileProxy --> onServiceConnected profile:" + profile + (proxy == null));
                    if (proxy != null) {
                        LogUtil.d(proxy.getClass().getName());
                        BluetoothUtil.disconnectedDevice(mConnectedDevice, proxy);
                    }
                }

                @Override
                public void onServiceDisconnected(int profile) {
                }
            }, BluetoothUtil.INPUT_DEVICE_PROFILE);
        }
    }
    public static boolean disconnectedDevice(BluetoothDevice device, BluetoothProfile profile) {
        try {
            Method method = profile.getClass().getMethod("disconnect", BluetoothDevice.class);
            method.invoke(profile, device);
            return true;
        } catch (Exception e) {
            LogUtil.d(e.getMessage());
        }
        return false;
    }