簡體   English   中英

Android:通過ADB授予權限

[英]Android: Grant permissions through 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"/> 

但是當我嘗試使用以下命令通過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授予權限。 我引用了這個這個這個 但我仍然無法弄清楚為什么它不起作用的原因。

提前感謝您的建議和建議。

首先,讓我們連接您計算機上的手機,讓我們看看安裝了多少個應用程序:

>> ./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
adb shell pm [grant|revoke] [package] android.permission.CAMERA

使用adb shell命令

有關adb的進一步說明授予/撤銷權限,請參閱此處

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM