tezvyn:

PermissionsAndroid: Requesting Runtime Permissions

AI-drafted, machine-checkedSource: reactnative.devintermediate

PermissionsAndroid lets you ask for sensitive permissions like camera or location at runtime. Use its `request` method to show the native Android dialog. The biggest footgun is ignoring the `NEVER_ASK_AGAIN` result, which requires sending the user to system…

WHY IT EXISTS: Before Android 6.0 (SDK 23), users granted all permissions at install time. This was an all-or-nothing deal. The modern model improves privacy by letting users grant sensitive permissions only when an app needs them. PermissionsAndroid is the React Native API that bridges this native, runtime-request functionality.

THE MENTAL MODEL: Think of it as a gatekeeper for sensitive device features. You can't assume you have access to the camera or contacts. You must first knock on the door (check), and if it's locked, you must politely ask for the key (request). The user can grant access, deny it, or tell you to stop asking entirely.

HOW IT WORKS: The API has two primary methods. First, PermissionsAndroid.check(permission) returns a promise resolving to a boolean indicating if permission is already granted. Second, PermissionsAndroid.request(permission, rationale?) prompts the user with the system dialog. This returns a promise resolving to a result string: GRANTED, DENIED, or NEVER_ASK_AGAIN. The optional rationale argument displays an extra dialog explaining why you need the permission, but only if the user has denied it before.

WHEN TO USE IT: Use this in any React Native app (not using managed Expo) that needs to access a "dangerous" permission on Android. This includes location, camera, contacts, storage, and more. It is an Android-only API; iOS has a separate permission flow.

WHEN NOT TO USE IT: Do not use this for iOS. Also, if you are using the managed Expo workflow, use Expo's own permissions library instead. This API is intended for projects where you have direct access to the native Android project files. It is also unnecessary for "normal" permissions that are granted automatically at install.

ONE CANONICAL EXAMPLE: To use the camera, you would first call await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.CAMERA). If this is false, you then call await PermissionsAndroid.request(...). If the result is GRANTED, you can open the camera. If DENIED, you should disable the camera feature. If NEVER_ASK_AGAIN, you must disable the feature and provide a button that deep-links the user to your app's system settings, as you cannot prompt them again.

Read the original → reactnative.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.