Android Marshmallow Run Time Permissions

Prior to Android Marshmallow when ever you install an application from Google Play Store, it opens a dialog box which contains a list of permission that app needs in order to work properly.

But after Android Marshmallow and above that dialog box was replaced with something called RUN TIME PERMISSIONS.

You have often noticed that when you are using an Android Application all of a sudden a dialog box appears, Which asks for accessing your contacts or your location etc. This is what Run time Permissions are.

Old Permission model was so simple, why they included run time permissions in  Android?

The only answer is for more user awareness and security. User should know what they are doing with an app and how app is working behind the scene.

What is the need of Android Run time Permissions?

Imagine you downloaded a Music Player application. The application asks for dozens of permission when you installed the app. One of the permission is to access your contact list. Suppose you are playing a song, in the mean while the app is accessing all of your contact list and uploading it to server. Here lies the problem user privacy compromised.

So the main reason behind Run time Permission is to make user aware why the app needs that permission.


Do I need to write code to implement Run time Permission?

Yes. We need to write a bit of code to implement Marshmallow Permission Model.


There are basically 2 types of Permission in Android :

1> Normal Permission

Permission which are very common and do not have any concern with user privacy.

ex – Internet Permission etc.

2> Dangerous Permission

Permission which can use your private information.

ex – Location Service, SMS Service etc.

If you want to read more about these permission follow this link.


For this Purpose I have created an example which accesses multiple permission at a same time. Keep in mind that you should only ask for particular permission when you need to access that feature.

Let’s jump to our example.

First Create a new project from File -> New -> New Project, Name it Marshmallow Permission & Select Empty Activity (We will build everything from scratch).

1> Now in your AndroidManifest.xml write below code.


2> Now in your write below code.

Important Notes :

1> Always perform a check on Android Version. New Permission Model is introduced in Android Marshmallow. Application will crash if Android Version check is not performed.

2> Even if we implement run time permissions, we need to mention all required permission same old style in AndroidManifest.xml. This is for older version of android.


3> Sometime you need to explain why the application needs this permission that can be done using this code.


That’s all we have to do. No need to change anything in Gradle file our Layout files.

If you have any error write down in comment. If you want any particular tutorial do let me know in comments.

Leave a Reply

Your email address will not be published. Required fields are marked *