![]() |
VOOZH | about |
The Runtime Permission in Android which introduced in Marshmallow and due to these runtime permissions users can grant permission to the app in runtime, also while writing the code for runtime permissions. Sometimes handling the task of requesting permissions becomes so difficult and the developer has to write a huge amount of code. So we will see the Implementation of Runtime Permissions in Android using Dexter.
Dexter is the library that will help us to make this task easy for handling Runtime Permissions in Android. Now we will see the implementation of this in our Android Application.
We will be building a simple application in which we will be showing a button to the user. After clicking on that button we will display runtime permissions to the user. So if the users deny the permission then we are showing the option to open the settings screen and grant the permissions. Below is the short video in which we will see what we will build in this article.
To create a new project in Android Project just refer to this article on How to Create New Project in Android Studio. The code has been given in both Java and Kotlin Programming Language for Android.
Navigate to gradle scripts and then to build.gradle(Module) level. Add below line in build.gradle file in the dependencies section.
implementation 'com.karumi:dexter:6.2.2'
After adding this dependency now sync your project. Let's move toward the XML part.
Go to the activity_main.xml File and refer to the following code. Below is the code for the activity_main.xml File.
Go to the MainActivity File and refer to the following code. Comments are added inside the code to understand the code in more detail.
Navigate to the app > AndroidManifest.xml file and add the below permissions to it.
After adding these permissions to our AndroidManifest.xml file. Now run our app and see the output of the code.