58

The Android documentation contains the following description of the adb grant and adb revoke commands.

grant <PACKAGE_PERMISSION>

Grant permissions to applications. Only optional permissions the application has declared can be granted.

revoke <PACKAGE_PERMISSION>

Revoke permissions to applications. Only optional permissions the application has declared can be revoked.

Can anybody please give an example of the correct syntax to use them?

I assume that would be a permission like android.permission.WRITE_EXTERNAL_STORAGE, or perhaps just WRITE_EXTERNAL_STORAGE. Well I tried those, and several others and I cannot get it to work.

I also tried (to no avail) several combinations of package and permission, which makes more sense to me (this sounds like a command that would modify a permission on one package, not all)

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
gabriel
  • 1,163
  • 2
  • 9
  • 15

3 Answers3

103

To Add:

adb shell pm grant com.name.app android.permission.READ_PROFILE

To Remove:

adb shell pm revoke com.name.app android.permission.READ_PROFILE

This changed at the release of Android M, so in Lollipop (at original time of writing answer) you needed to do adb shell first.

adb shell 
pm grant com.name.app android.permission.READ_PROFILE

A full list of permissions can be found here. If you have android build tools set up you can see what permissions the app is using. First use

adb shell pm list packages -f

Then copy the package to you computer:

adb pull /path/to/package/from/previous/step.apk

Then get permissions:

aapt d permissions path/to/app/on/computer.apk
Cynic
  • 6,779
  • 2
  • 30
  • 49
7

If you happen to not know the name of permission or want to clear all permissions you can use

adb shell pm reset-permissions

WARNING: This will reset run-time permissions for all the apps on your phone. You cannot reset for a specific package.

Susheel Karam
  • 837
  • 7
  • 16
ar-g
  • 3,417
  • 2
  • 28
  • 39
  • 21
    **Be careful with this command since it reset all your system permissions.** pm reset-permissions is parameterless. It doesn't care about your.package.name. – Stanislaw Baranski Nov 09 '17 at 12:33
  • 1
    what does reset mean in this context? revoke all permissions? Or set them to whatever the manifest of the app wants? – Frederick Nord Jul 07 '19 at 18:35
5

So here's a little command line (mac/linux) to grant your app all of the permissions it requires from the command line.

aapt d permissions ./path/to/your.apk \
  | sed -n \
    -e "s/'//g" \
    -e "/^uses-permission: name=android.permission\./s/^[^=]*=//p" \
  | xargs -n 1 adb shell pm grant com.your.package
JohnnyLambada
  • 12,700
  • 11
  • 57
  • 61
  • 1
    Note: After pasting in the command I discovered I needed to remove the first of the '\' characters (immediately after the apk file name) in order for the sed command to run correctly. – JulianHarty Aug 21 '19 at 14:12