Android:通过 ADB 授予权限

KTB*_*KTB 7 permissions android

对于我的应用程序的某些功能,我需要使用相机,这不是应用程序的核心功能所必需的,因此我需要指定使用相机是可选的。所以在清单中我声明了如下许可:

<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/> 
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用以下命令通过 adb 授予权限时,会出现错误:

pm grant my.app.package android.permission.CAMERA
Run Code Online (Sandbox Code Playgroud)

给出错误:

Operation not allowed: java.lang.SecurityException: Can't change android.permission.CAMERA. It is required by the application
Run Code Online (Sandbox Code Playgroud)

我的设备是根设备,它运行 android 5.1.1(22)。根据亚行文档,由于权限被声明为可选,我应该能够如上所述从亚行授予权限。我已经参考了这个这个这个。但我仍然无法找出它不起作用的原因。

预先感谢您的建议和建议。

Aks*_*pde 5

首先,让我们在电脑上连接一个手机,看看安装了多少个应用程序:

>> ./adb shell pm list packages
Run Code Online (Sandbox Code Playgroud)

您将获得包名称列表:

[...]
com.google.android.GoogleCamera
[...]
Run Code Online (Sandbox Code Playgroud)

现在我们将获得所有权限的列表:

>> ./adb shell pm list permissions -d -g

[...]
group:android.permission-group.CAMERA
  permission:android.permission.CAMERA
[...]
Run Code Online (Sandbox Code Playgroud)

这里是如何撤销权限:

>> ./adb shell pm revoke com.google.android.GoogleCamera  android.permission.CAMERA
Run Code Online (Sandbox Code Playgroud)

在这里如何授予它:

>> ./adb shell pm grant com.google.android.GoogleCamera android.permission.CAMERA
Run Code Online (Sandbox Code Playgroud)


Tom*_*thu 1

adb shell pm [grant|revoke] [package] android.permission.CAMERA
Run Code Online (Sandbox Code Playgroud)

使用 adb shell 命令 \

请参阅此内容以进一步说明使用 adb 授予/撤销权限