Skip to content

Android Runtime Permissions Rationale Dialog Positive | Negative Buttons #13920

@okarakose

Description

@okarakose

Description

We have runtime permissions in our application like almost all applications.
When user denies permission, need to explain "Why we need this permission" in rationale dialog. Title and Message can add but positive and negative buttons can not add for Android AlertDialog. Actually, it is not using AlertDialog for android platform.

From react-native documentation for PermissionsAndroid

https://facebook.github.io/react-native/docs/permissionsandroid.html

there are mentioned about Title and Message but nothing about Positive & Negative buttons.

Reproduction Steps and Sample Code

Example Code

import { PermissionsAndroid } from 'react-native';

export const RequestAndroidPermission = (permission,rationale) => {

    return new Promise((resolve, reject) => {

        PermissionsAndroid.check(permission)
            .then(grantedPreviously => {
                if (grantedPreviously) {
                    resolve()
                } else  {
                    PermissionsAndroid.request(permission, rationale)
                        .then(granted => {
                            if (granted === PermissionsAndroid.RESULTS.GRANTED) {
                                resolve()
                            } else {
                                reject()
                            }
                        }).catch( e => reject(e))
                }
            }).catch(e => reject(e))

    })

}

const locationPermissionType = PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
const locationPermissionRationale = {
    title: "Location Access",
    message: 'Need for detect your location to select location nearby you easily'
    // how to create Positive and Negative alert dialog button here ?
}
export const RequestAndroidLocationPermission = () => RequestAndroidPermission(locationPermissionType,locationPermissionRationale)

Solution

I tried to follow the code flow, it is passing over android Dialog but I could not see the code which is called from.

Additional Information

  • React Native version: 0.43.4
  • Platform: Android ( iOS did not check yet )
  • Development Operating System: Not important for this issue
  • Dev tools: Not important for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions