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

时间:2019-04-10 17:38:09

标签: android bluetooth permissions android-permissions

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

如何获取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.

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

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

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

0 个答案:

没有答案