Exploring Android 12: Data Access Rationale

Android 12 introduces a new privacy feature for users which is Data Access Rationale.

What is Data Access Rationale?

Data access rationale is basically an Activity that provides an explanation why your app uses a certain permission.

This Activity can be accessed through 2 methods.

The first method is by going to your app’s App Info page. Here’s how to do it:

  1. Hold-click your app icon.
  2. Click App info. A settings page will appear.
  3. Click Permissions.
  4. Click the info icon that is located beside a permission (See image below).
Click the info icons to open Data Access Rationale from App Info page.

The second method is by going to Privacy Dashboard page. Here’s how to do it:

  1. Open Settings app.
  2. Click Privacy > Privacy dashboard.
  3. In the Privacy dashboard page, select one of the permissions listed on the page that your app uses (e.g., Location).
  4. Click the info icon that is located beside your app (See image below).
Click the info icons to open Data Access Rationale from Privacy Dashboard page.

The info icons shown above do not appear magically. Developers have to implement some code to be able to make the icons visible.

In this article, we will create a simple application to show you how to implement this Data Access Rationale.

Where’s the Source Code?

Step by Step Explanation

The application that we will create is a simple app that uses Location permission to get user device’s current location. This permission is not directly related to Data Access Rationale. However, we have to use a permission so that our app appears in the Privacy dashboard page.

Follow the steps provided below to create this application.

1. Open Android Studio. Create new project with “Empty Activity” option.

2. Add a dependency to app/build.gradle file. This dependency is needed to get device’s current location.

3. Next, add ACCESS_COARSE_LOCATION permission to AndroidManifest.xml file.

4. Next, we need to update our MainActivity.kt file. You can go ahead and copy-paste the code snippet below. It’s quite long but the logic is quite simple. When first launched, this Activity will ask for Location permission. If user grants this permission, the app will proceed to get device’s current location. This Activity sole purpose is so that our app uses Location permission, so that our app will appear in the Privacy Dashboard page. On the next step, we will finally code our Data Access Rationale Activity.

5. We will begin creating our Data Access Rationale Activity. Create a new Activity by clicking menu File > New > Activity > Empty Activity. In the popup dialog that appears, Fill Activity Name field with “DataRationaleActivity” and Layout Name field with “activity_data_access_rationale”. Click Finish to create the Activity.

6. Next, we will update the layout first. Open activity_data_access_rationale.xml file that you just created and copy-paste the code snippet below:

The layout should look like something like this:

What activity_data_access_rationale.xml file looks like.

7. Next, we need to update our DataAccessRationaleActivity.kt file. Go ahead and copy-paste the code snippet below. The main point to know about this Activity is the Intent. This Activity will be launched (through Intent) whenever user clicks on the info icons in the App Info or Privacy Dashboard page. And inside these launch Intents, developer can get information such as:

  • The origin of Intent (App Info page or Privacy Dashboard page)
  • The permission group (e.g., Location permission)
  • The start time and end time (only when opened through Privacy Dashboard page)

In this article, we will simply displays these information in TextViews. However, in real apps, you usually want to utilize these information to display the correct rationale based on the permission group.

8. Lastly, we are going to update our AndroidManifest.xml file, specifically we are going to export our Data Access Rationale Activity and register IntentFilter for it. By registering VIEW_PERMISSION_USAGE, an info icon will appear in our app’s App Info page. And by registering VIEW_PERMISSION_USAGE_FOR_PERIOD, an info icon will appear in the Privacy Dashboard page.

9. That’s it! Now we can begin testing this application. First, we need to run the app normally like shown in the image below. Make sure to enable Location service and grants permission to the app. Wait until a Toast appears that says device’s current location is retrieved. This is done so that our app will appear in the Privacy Dashboard page.

Before opening Data Access Rationale, open the app normally for the first time until the app finishes retrieving device’s current location.

10. Finally, you can open App Info or Privacy Dashboard page (as specified in the instructions above) and you will able to see your Data Access Rationale Activity in action like this:

Open our app’s Data Access Rationale through App Info page.
Open our app’s Data Access Rationale through Privacy Dashboard page.

As always, thanks for reading!

Want to learn more about Android 12?

Check out all of our articles from “Exploring Android 12” series here:

Exploring Android 12

9 stories

--

--

--

Android Engineer @ Bobobox.co.id

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Simple Implementation of Android Preferences DataStore

Visual Transformation for any mask in Jetpack Compose TextField

Diving into Flutter Widget (P3)

Covid Notifier India

Improving CI/CD pipeline for Android via Fastlane and GitHub Actions

Android: Aab Bundles, install on Devices

Securing Personally identifiable information in Android using Jetpack Security

Android: Google Maps Clustering

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Farhan Majid 🐾

Farhan Majid 🐾

Android Engineer @ Bobobox.co.id

More from Medium

Master Coroutine in 2 Hours: Free Course

Exploring Android 12: Permission Group Lookup

Listening to your Android App

Kotlin Coroutines Basics — Simple Android App Demo