Android TutorialsNo Comments

default thumbnail
492 views.

Android M has brought a new interesting feature, i.e. Runtime Permission. Unlike previous version, android devices now requires it’s users to allow or deny to access few of their device information.

Android defined some permission s “Dangerous” and some permissions as “Normal”. Both are required in your application’s manifest but only dangerous requires a runtime request. Normal permissions are accepted at install time and can not be revoked later, An example of a normal permission is android.permission.Internet.

Dangerous permission are grouped into categories that makes it easier for the user to understand what they are allowing the application to do. If the user accepts one permission in a group they accpet the entire group. the opposite is true as well, if the user denies one permission in a group, the entire group is denied.

for example, if an application if using FINE_LOCATION and COARSE_LOCTION permisions of the same group LOCATION. Then if user granted permission for one , the app will automatically grant permission for the second.

The below table show the dangerous permission and the group they belongs to:

permission_chart

Let’s begin our example:

1. Suppose, in an application you are using Camera and Location permission, then declare permissions in AndroidManifest.xml:

2. Now, we will be asking for these two permissions one by one. First for location, second for camera.

In our screen there will be two button to check if permissions are already granted and another to request permissions:

3. Layout is like this: activity_main.xml

4. content_main.xml:

5. And finally, this is my app gradle file:

6. Screenshots of the app are here:

screenshot_20160515-162203 screenshot_20160515-162055 screenshot_20160515-162211

Be the first to post a comment.

Add a comment