首页 > 解决方案 > 如何获得 BLUETOOTH_PRIVILEGED 权限以在路由设备中自动配对设备而不将其放在系统应用程序中?

问题描述

我需要 BLUETOOTH PRIVILEGED 权限才能自动配对设备

如何获得 BLUETOOTH_PRIVILEGED 权限以自动配对设备中的设备而不将其放在系统应用程序中?

我正在尝试使用已在 ListView 中显示的一个设备以编程方式自动修复而不显示“配对对话框”

IntentFilter filter = new IntentFilter("android.bluetooth.device.action.PAIRING_REQUEST");
        registerReceiver(new PairingRequest(), filter);

//接收者

public static class PairingRequest extends BroadcastReceiver {
    public PairingRequest() {
        super();
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("android.bluetooth.device.action.PAIRING_REQUEST")) {
            try {
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                int pin = intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY", 0);
                //the pin in case you need to accept for an specific pin
                Log.d("PIN", " " + intent.getIntExtra("android.bluetooth.device.extra.PAIRING_KEY",0));
                //maybe you look for a name or address
                Log.d("Bonded", device.getName());
                byte[] pinBytes;
                pinBytes = (""+pin).getBytes("UTF-8");
                device.setPin(pinBytes);
                device.setPairingConfirmation(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

但是在调用 device.setPairingConfirmation(true);它之后会出现异常并出现此错误java.lang.SecurityException: Need BLUETOOTH PRIVILEGED permission: Neither user 10069 nor current process has android.permission.BLUETOOTH_PRIVILEGED.

我已经进行了搜索,所有建议都是将应用程序放在系统/应用程序中,但我不能放在那里,因为我需要在未来进行更新。

我正在使用的设备已植根,并且应用程序位于“数据/应用程序”路径中

任何建议都会有所帮助。非常感谢!

标签: androidbluetoothpermissionsandroid-permissions

解决方案


推荐阅读