Android 11: Managing Permissions

Jay Patel
PHP Poets
Published in
2 min readNov 2, 2020

--

Android 11 is here, and stable SDK support for “R” hits Android Studio. This new version has introduced many behavioral changes that affect all the apps you might be working on. Your apps might need some changes to support the platform to function correctly. In Android 11, Privacy and Security are at the highest priority. One of the features I found easy to implement is managing permissions. It is the right time to say goodbye to our old friend startActivityForResult(). Thanks to the Android 11 Register Activity For Result API. It provides components for registering for the results launching the result and handling the work once the system dispatches it. Activity Result APIs introduced in AndroidX Activity 1.2.0-alpha02 and Fragment 1.3.0-alpha02.

Add Permissions to Manifest:

On all the versions of android, You must declare <user-permission> element in your AndroidManifest.xml file.

<uses-permission android:name="android.permission."/>

Android has introduced a feature for handling the privacy permissions, aka the dangerous permissions in Android API level 23 and higher (Android 6.0), to make developers alert a dialog to request permissions.

Add an AndroidX library for the dependencies, which has to be 1.2.0 or later. The library is mentioned above.

You can handle single and multiple permissions by RequestPermission and RequestMultiplePermission.

In your activity or fragment’s initialization logic, pass in an implementation of ActivityResultCallback into a call to registerForActivityResult(). The ActivityResultCallback defines how your app handles the user’s response to the permission request.

After the user responds to the system permissions dialog, the system then invokes your app’s implementation of onRequestPermissionsResult()

There are three scenarios a user can create while requesting permissions. Either he can grant or deny the permissions. But from Android 9.0, the permissions are changed to Allow for this time, Allow for every time and Deny options. If the user denied, you could also use ShowRequestPermissionRationale() to guide them to an educational UI to show them why the feature or permission is essential to access for your app.

Android 11 grant permissions dialog
Android 6.0 grant permission screens

Some 3rd Party Permission Library I use:

  1. RxPermissions
  2. Dexter Permissions

A simple project in Android 11 Permissions using Register Activity For Results APIs :

--

--

Jay Patel
PHP Poets

Software Engineer @QBurst || IITP '25 Cloud Computing