Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ShouldShowRequestPermissionRationale(string)

Check whether to display the UI explaining the reason for permission before requesting it.
Read time 1 minuteLast updated 10 days ago

Definition

public static bool ShouldShowRequestPermissionRationale(string permission)

Parameters

permission

A string identifier for permission. This is the value of Android constant.

Returns

Type

Description

boolThe value returned by equivalent Android method.

Remarks

For more information on this method, refer to Android developer documentation.

Examples

using UnityEngine;using UnityEngine.Android;public class RequestPermissionScript : MonoBehaviour{ internal void PermissionCallbacks_PermissionDeniedAndDontAskAgain(string permissionName) { Debug.Log($"{permissionName} PermissionDeniedAndDontAskAgain"); } internal void PermissionCallbacks_PermissionGranted(string permissionName) { Debug.Log($"{permissionName} PermissionCallbacks_PermissionGranted"); } internal void PermissionCallbacks_PermissionDenied(string permissionName) { Debug.Log($"{permissionName} PermissionCallbacks_PermissionDenied"); } void Start() { if (Permission.HasUserAuthorizedPermission(Permission.Microphone)) { // The user authorized use of the microphone. } else { // The user has not authorized microphone usage. // Check whether you need to display the rationale for requesting permission bool useCallbacks = false; if (!useCallbacks) { if (Permission.ShouldShowRequestPermissionRationale(Permission.Microphone)) { // Show a message or inform the user in other ways why your application needs the microphone permission. } // Ask for permission or proceed without the functionality enabled. Permission.RequestUserPermission(Permission.Microphone); } else { var callbacks = new PermissionCallbacks(); callbacks.PermissionDenied += PermissionCallbacks_PermissionDenied; callbacks.PermissionGranted += PermissionCallbacks_PermissionGranted; callbacks.PermissionDeniedAndDontAskAgain += PermissionCallbacks_PermissionDeniedAndDontAskAgain; Permission.RequestUserPermission(Permission.Microphone, callbacks); } } }}