Android:通过ADB授予权限
问题描述:
对于我的某些功能应用程序,我需要使用相机,这对于应用程序的核心功能不是必需的,所以我需要指定它是可选的使用相机。因此,在清单我宣布同意如下:Android:通过ADB授予权限
<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"/>
但是当我尝试使用以下命令授予亚行批准它给出了一个错误:
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)。根据亚行documentation,由于权限被声明为可选,因此我应该能够如上所述从adb授予许可。我参考了this,this和this。但是我仍然无法弄清楚它不工作的原因。
非常感谢您的建议和意见。
答
adb shell pm [grant|revoke] [package] android.permission.CAMERA
利用亚行shell命令\
请参阅本作进一步澄清grant/revoke permission with adb
答
首先,让我们在连接手机您的计算机上,让我们看看有多少应用程序安装:
>> ./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