0

Share

APP DEVELOPMENT

How To Manage Runtime Permissions With Dexter In Android?

  • Home
  • Blogs
  • How To Manage Runtime Permissions With Dexter In Android?

Dexter is an Android library to simplify the process of requesting permissions at runtime, where they can accept or reject permission while using an application.

Somish Kakadiya

July 15, 2022

You have seen many applications in which they ask for certain permission to allow or deny according to your choice. But an application makes the features work better for you when you give them access to certain details or other things.

Android Marshmallow offers a new function (Dexter) that allows users to accept or reject permission while using the application, instead of accepting them all during the app installation.

In this blog, we are going to simplify the process of adding the runtime permissions using the Dexter library. Using this library, the permissions can be implemented in few minutes.

Dexter Permissions Library

To get started with Dexter, Include the library in your build.gradle

Requesting Single Permission

To request single permission, you can use withPermission() method by passing the required permission. You also need a PermissionListener callback to receive the state of the permission.

onPermissionGranted() will be called once the permission is granted.

onPermissionDenied() will be called when the permission is denied. Here you can check whether the permission is permanently denied by using response.isPermanentlyDenied() condition.

The below code requests READ_SMS permission.

To request multiple permissions at the same time, you can use withPermissions() method. Below code requests READ & WRITE STORAGE and READ & WRITE CONTACTS permissions.

Error Handling

You can also catch any errors occurred while integrating the library using PermissionRequestErrorListener.

Now Let’s See How To Use Dexter In An Example Project.

Creating New Project

Create a new project in Android Studio from File ⇒ New Project and select Empty Activity from templates.

Include the library in your build.gradle

Add following permissions in AndroidManifest.xml

Test Permission Methods

Open the layout file of your MainActivity.java (activity_main.xml) and add two buttons to test single permission & multiple permission methods.

Open MainActivity.java and update it

Screenshots




This is an introductory article about the Dexter covering basic features offered by the library. Dexter provides other features like using it with SnackBar, different types of listeners, error handling and few other. You can find more information on Dexter’s developer page.

Conclusion:

This blog was wrapped around the process of adding runtime permissions using the Dexter library. It will be helpful to learn and practice it, to develop the client's application with and use this function to give them the best-featured app.



img

Somish Kakadiya

CTO of Vasundhara Infotech, a leading Software development company in the USA. His technological interests has helped the company in making useful decisions.

message

Have a project in mind? Drop a message to Bansi Pipaliya & start the discussion!

Get a Newsletter

Sign Up to our newsletter to get latest updates staight in your inbox.

Vasundhara respects your privancy. No Spam!

Get a Newsletter

Sign Up to our newsletter to get latest updates staight in your inbox.

Vasundhara respects your privancy. No Spam!

message

Have a project in mind? Drop a message to Bansi Pipaliya & start the discussion!

Latest 13 Web Development Trends To Expect In 2022
April 11, 2022 Category : company news

Revealing Vasundhara’s New Identity

Read More
Latest 13 Web Development Trends To Expect In 2022
May 17, 2022 Category : web development

Latest 13 Web Development Trends To Expect In 2022

Read More
Leave a Comment