【问题标题】:Android: Grant permissions through ADBAndroid:通过 ADB 授予权限
【发布时间】:2018-03-21 09:11:27
【问题描述】:

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

<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

我的设备是有根的,它运行 android 5.1.1(22)。根据 ADB documentation,由于权限被声明为可选,我应该能够像上面提到的那样从 adb 授予权限。我参考了thisthisthis。但是我仍然无法弄清楚它为什么不起作用的原因。

提前感谢您的建议和建议。

【问题讨论】:

  • 可以直接放在你的App代码中吗?

标签: android permissions


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:
    adb shell pm [grant|revoke] [package] android.permission.CAMERA
    

    使用 adb shell 命令\

    请参阅此以进一步澄清grant/revoke permission with adb

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-30
      • 1970-01-01
      • 2016-10-07
      • 1970-01-01
      • 2016-03-08
      • 1970-01-01
      相关资源
      最近更新 更多