如何在没有 root 的情况下使用 adb 授予权限? [英] How can I use adb to grant permission without root?

查看:38
本文介绍了如何在没有 root 的情况下使用 adb 授予权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

我正在尝试创建一个可以授予和撤销其他应用权限的应用.
为此,我使用 adb 命令:

I'm trying to create an app that can grant and revoke permissions of other apps.
To do this I'm using adb commands:

pm grant packageName permissionName

如果我通过具有 root 权限的 shell 调用它,这很有效.

This works great if I call it through a shell with root permissions.

问题

问题是当我在没有root权限的情况下调用这个命令时,我收到

The problem is that when I call this command without root permissions, I receive

不允许操作:java.lang.SecurityException:grantRuntimePermission:用户 2000 和当前进程都没有android.permission.GRANT_RUNTIME_PERMISSIONS

Operation not allowed: java.lang.SecurityException: grantRuntimePermission: Neither user 2000 nor current process has android.permission.GRANT_RUNTIME_PERMISSIONS

这是意料之中的(否则这将是一个大问题).

This is to be expected (it would be a big problem otherwise).

问题

是否可以允许我的应用通过 Android 设置管理其他应用的权限?
我正在寻找类似授予 USAGE_STATS 权限的应用程序,转到设置 -> 安全性 ->具有使用权限的应用程序",但对于 GRANT_RUNTIME_PERMISSIONS(和 REVOKE_RUNTIME_PERMISSIONS).

Is it possible to allow my app to manage other apps permissions through Android settings?
I'm looking for something like granting USAGE_STATS permission to an app going to Settings -> Security -> "App with usage access", but for GRANT_RUNTIME_PERMISSIONS (and REVOKE_RUNTIME_PERMISSIONS).

推荐答案

我试图将 BBS 安装到我的 Redmi Note 4, MIUI 10.1(不确定细节是否相关).得到同样的错误.然后我在开发人员选项中的USB 调试"主菜单下方三行找到了一个菜单项.它被称为

I was trying to install BBS to my Redmi Note 4, MIUI 10.1 (not sure if details are relevant). Got same error. Then I found a menu item three rows below main 'USB debugging' menu in developer options. It was called

USB 调试(安全设置)

允许通过 USB 调试授予权限和模拟输入

尝试启用此选项会提示三个警告窗口,其中包含有关如果继续操作可能会发生的可怕事情的信息.上次确认后(不确定手机是否已连接或我之后连接)我跑了

Attempt to enable this option prompted three warning windows with information about terrible things that can happen if you proceed. After last confirmation (not sure if the phone was connected or I connected it after) I ran

adb -d shell pm grant packageName android.permission.BATTERY_STATS

但现在它成功了.

这篇关于如何在没有 root 的情况下使用 adb 授予权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆