Check Multiple Android Kotlin Runtime Permissions Programmatically

Hi, Guys. Welcome to Android Kotlin Runtime Permissions example.

In this tutorial, We will learn how to programmatically request multiple Android Kotlin Runtime Permissions.

From android’s Marshmallow version, the developer needs to programmatically check and request multiple Android Kotlin Runtime Permissions to the user.

Using our code, you can ask for multiple or single runtime permissions android as per your requirements.

Following is the output:

Download Source Code For Check Multiple Android Kotlin Runtime Permissions

[sociallocker]Kotlin_MarshmallowPermission[/sociallocker]

Understanding Runtime Permissions Architecture

As you have seen in the video, a dialog is created for asking every permission.

If the user denies, it will again ask when the user opens an Android app.

Once user allows, it will never ask for same permission in the future.

There is also one checkbox saying “Never ask again,” if the user clicks on that and then after deny, then Android will never ask for that permission.

For handling above situation, Android opens another dialog which allows the user to go to setting of our app and from there, he can turn on and off various permissions.

Following are required code snippets.

Step 1: Creating WelcomeActivity.kt class:

Create new Activity named WelcomeActivity.kt and add below code

Update activity_welcome.xml as below

Step 2: Creating MainActivity.kt class:

Step 3: Description of MainActivity

Defining permission codes

In checkAndRequestPermissions() method, create permission code for each permission like below.

Preparing ArrayList

Add each permission in ArrayList and ask user by below source code

Hashmap Creation

In onRequestPermissionResult() method, put all permission in one Hashmap.

Now check if all permissions are granted or not.

If granted, open WelcomeActivity or continue to the normal flow of your app.

If not granted, then ask again with your message.

Update Package name

In explain() method you need to update package name in below line

Define required permissions in AndroidManifest.xml

What are Normal Permissions?

Now, notice one thing. We have to define INTERNET permission in manifest file but have not ask for same in MainActivity.java class.

Android has classified some permissions as Normal Permissions, which are not very dangerous for user’s security and that’s why we don’t need to ask for those normal permissions but need to define them in the Manifest file.

You can find some more details and list of normal permissions here on an official document.

Java Version

Java version of this tutorial : Runtime Permissions Android Studio.

If you have any question about implementing check request multiple android kotlin runtime permissions, feel free ask in the comment section.

Cheers and happy coding!

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

Leave a Reply

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