2

What is the difference between requestedPermissions and permissions?

PackageInfo _pi = getPackageManager().getPackageInfo(this.getPackageName(), 
                                               PackageManager.GET_PERMISSIONS);

// permissions
PermissionInfo[] _permissions = _pi.permissions;

// requestedPermissions
String[] _requestedPermissions = _pi.requestedPermissions;

Is it about application's permissions and OS's permissions?

Thanks

Yousha Aleayoub
  • 4,532
  • 4
  • 53
  • 64
  • 1
    Requested permissions, I believe, are permissions that are requested, but have not necessarily (yet) been granted. `PermissionInfo` is about the permission itself https://developer.android.com/reference/android/content/pm/PermissionInfo.html. See this question http://stackoverflow.com/q/18573139/1256219 for checking requested permissions and confirmation in the comments – brandall Sep 10 '16 at 02:59

2 Answers2

2

As in the documentation

public PermissionInfo[]

Array of all <permission> tags included under <manifest>, or null if there were none.

and

int[] requestedPermissions

Array of all <uses-permission> tags included under <manifest>, or null if there were none.

so permissionInfo will have the attributes in manifest tag in manifest for e.g.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.androidtest"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name">

and

requstedPermissions will return the permissions in <uses-permission>tag for e.g

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CAMERA" />
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
Nikhil
  • 3,711
  • 8
  • 32
  • 43
  • 1
    I don't think you are correct. `PermissionInfo` contains information regarding the permission itself? https://developer.android.com/reference/android/content/pm/PermissionInfo.html – brandall Sep 10 '16 at 02:52
  • @brandall refer [this](https://developer.android.com/reference/android/R.styleable.html#AndroidManifestPermission) – Nikhil Sep 10 '16 at 02:55
  • I think the first part (`permissionInfo`) is not true... but the second part is. I found this from docs: `permissionInfo` Is information you can retrieve about a particular security permission known to the system. This corresponds to information collected from the AndroidManifest.xml's `` tags. https://stackoverflow.com/questions/14450839/ – Yousha Aleayoub Sep 10 '16 at 03:09
  • @downvoter it is best practice to comment the reason of downvoting – Nikhil Nov 21 '16 at 05:53
-1

if you want get all permissions pre checked in manifest you must use code below:

private bool PermissionInManifest (string permission)
{
    var permissions = this.Activity.PackageManager.GetPackageInfo(this.Activity.PackageName, PackageInfoFlags.Permissions);
    var requestedPermissions = permissions.RequestedPermissions.ToList();
    return requestedPermissions.Contains(permission);
}

if you want check permission granted by user or not, you can use:

private bool PermissionGranted (string permission)
{
    return this.Activity.PackageManager.CheckPermission (permission, this.Activity.PackageName) == Permission.Granted;
}
Danil Shaykhutdinov
  • 2,027
  • 21
  • 26