android - 如何获得 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.
我已经进行了搜索,所有建议都是将应用程序放在系统/应用程序中,但我不能放在那里,因为我需要在未来进行更新。
我正在使用的设备已植根,并且应用程序位于“数据/应用程序”路径中
任何建议都会有所帮助。非常感谢!
解决方案
推荐阅读
- mongodb - 查询数组并忽略元素的顺序
- reactjs - Ionic/React - 浏览器自动填充输入项时如何从输入项中获取值?
- excel - 如何过滤然后填充到单独的工作表上?
- powershell - 从 html 元素中提取 http 链接
- python - pytest-cov - 不计算集成测试目录的覆盖率
- ios - iOS屏幕锁定时工作的音频播放器
- go - 一个 lambda 可以调用另一个 lambda,然后在子 lambda 完成之前退出吗?
- r - 如何将单个字符串分成R表中的列
- c# - 如何在构建时为 JetBrains Rider 转换 .Config?
- mysql - 如何将过时的 MySQL `SELECT * FROM table GROUP BY column1` 查询转换为更正 MySQL 8 语法?