Swapnil Swapnil - 2 months ago 9
Android Question

Run time permission app level or activity level

In the new api version of android (API 23), we now need to request the permission at the run time. I have a very basic doubt if the permission requested are app level or activity. According to this documentation you must check whether you have that permission every time you perform an operation that requires that permission. So does this mean that the permission is granted at app level but its check has been suggested to be done at the activity level? Also, the check for the permission has been suggested to be done as follows:

// Assume thisActivity is the current activity
int permissionCheck = ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.WRITE_CALENDAR);


Here, we clearly see that the check of the permission is done by passing the context of the activity. If the permission given is at app level why do we require the activity context and not the application context?(though there is a chance that the method internally gets the application context from the activity context.)

Answer

if the permission requested are app level or activity

All permissions in Android are for the entire app.

So does this mean that the permission is granted at app level but its check has been suggested to be done at the activity level?

The check to see if you have a permission can be done anywhere, via checkSelfPermission(). Requesting permission from the user has to be done from an activity, via requestPermissions(). The resulting permission grant will be for your entire app.

If the permission given is at app level why do we require the activity context and not the application context?

Any Context will work for ContextCompat methods.

Comments