Blog

Android Marshmallow 6.0 final stable version is released in October 2015. Android Marshmallow brought some new API changes and one of the most important API change is the addition of new granular permissions. Below is the type of permissions required for Marshmallow Devices:

In Marshmallow these dangerous permissions should be granted at run time and the normal permissions are granted automatically. For Lollipop (API level 22) or lower android versions the permissions specified in manifest are granted at installation.

Due to this permissions now no more popup dialog of permissions while installing app from Play Store. The permissions will be asked manually during run time via asking user to allow or deny the permissions. Below is the type of permissions dialog:

Pre – Marshmallow Devices Permissions Dialog :

Pre MarshMallow Permission

Marshmallow Devices Run Time Permissions Dialog :

Marshmallow Permission

You can navigate to App Info and go to Permission option to revoke back and grant access the permissions manually.

App Info Permission

Example

In this tutorial, we are going to learn how to check if the permission is already granted and if not granted how to grant permissions.

VIDEO DEMO

1. Create a new project in Android Studio by navigating to File ⇒ New ⇒ New Project and fill required details. By default my activity is MainActivity.java.

2. Open strings.xml located under res=>values folder and add following strings.

strings.xml

1

2

3

4

5

6

7

8

9

10

11

<resources>

<stringname="app_name">MarshMallow Permissions Demo</string>

<stringname="hello_world">Hello world!</string>

<stringname="action_settings">Settings</string>

<stringname="storage">Storage</string>

<stringname="sms">SMS</string>

<stringname="contacts">Contacts</string>

<stringname="location">Location</string>

<stringname="title">Click below buttons toallow permissions…</string>

</resources>

3.Create activity_main.xml and add the following code. In this xml file add the button to access permission.

5. Now to access permission for Marshmallow Devices below are some steps to do it:

Check if Permission is already granted : Lets check permission for ACCESS_FINE_LOCATION, if permission is granted then it will display toast else it will ask user to Allow or Deny the Location permission.

If Permission is not Granted Open Permission Dialog: If permission is not granted a dialog will open to ask user permission. Here we need to pass an Unique Id as we used to send in StartActivityForResult to get back result from user action.

Related

About the author

I am an Android developer for whom Android is the one and only love. I work as a freelancer which gets me and Android closer. I always love to share my learnings and love to learn from others knowledge too.

Check if Permission is already granted : Lets check permission for ACCESS_FINE_LOCATION, if permission is granted then it will display toast else it will ask user to Allow or Deny the Location permission.