Android:通过ADB授予权限

时间:2017-10-10 04:29:34

标签: android permissions

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

<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 documentation,由于权限被声明为可选,我应该能够如上所述从adb授予权限。我引用了thisthisthis。但我仍然无法弄清楚它为什么不起作用的原因。

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

2 个答案:

答案 0 :(得分:1)

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

使用adb shell命令\

请参阅此内容以进一步说明grant/revoke permission with adb

答案 1 :(得分:1)

首先,让我们连接您计算机上的手机,然后查看已安装的应用程序数量:

LPWSTR *szArgList;
int argCount;

 szArgList = CommandLineToArgvW((LPWSTR)GetCommandLine(), &argCount);
 if (szArgList == NULL){
     MessageBox(NULL, "Unable to parse command line", "Error", MB_OK);
     return 10;
 }
 int wint = 1;
 for(int i = 0; i < argCount; i++){
    cout << "szArgList[i]: " << (LPSTR)szArgList[i] << endl;
    string argsbek= (LPSTR)szArgList[i];
    if (argsbek.find(" passMyword") != string::npos){
       cout <<"words are passed ..."<<endl;
       wint=2;
    }
 }
 LocalFree(szArgList);

您将获得包名列表:

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