Android:通过ADB授予权限

7

为了我的应用程序的一些功能,我需要使用相机,这并不是应用程序核心功能所必需的,因此我需要指定其使用相机是可选的。因此,在清单文件中,我声明了以下权限:

<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"/> 

但是当我尝试使用以下命令通过adb授予权限时,会出现错误:
pm grant my.app.package android.permission.CAMERA

给出错误:

Operation not allowed: java.lang.SecurityException: Can't change android.permission.CAMERA. It is required by the application

我的设备已经root,并且运行的是Android 5.1.1(22)系统。根据ADB的文档,由于权限被声明为可选,我应该能够像上面提到的那样从adb中授予权限。我已经参考了thisthisthis。但是我仍然无法找出原因为什么它不起作用。
提前感谢您的建议和推荐。

你能直接把它放在你的应用程序代码里吗? - ralphgabb
2个回答

5

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

>> ./adb shell pm list packages

您将获得一个软件包名称列表:
[...]
com.google.android.GoogleCamera
[...]

现在我们要获取所有权限的列表:
>> ./adb shell pm list permissions -d -g

[...]
group:android.permission-group.CAMERA
  permission:android.permission.CAMERA
[...]

这里是如何撤销权限的方法:

>> ./adb shell pm revoke com.google.android.GoogleCamera  android.permission.CAMERA

以下是如何授予权限的方法:

>> ./adb shell pm grant com.google.android.GoogleCamera android.permission.CAMERA

我们如何为系统应用程序设置固定权限? - Ahmad

1
adb shell pm [grant|revoke] [package] android.permission.CAMERA

使用adb shell命令

如需进一步了解,请参阅使用adb授予/撤销权限


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接