askForPermission (Androidâ„¢)

Ask the user to enable a dangerous feature on the Android device.

Syntax

ui.Interface.frontCall("android","askForPermission",
  [permission], [result])
  1. permission - Identifies the Android permission to enable.
  2. result - Holds the execution status of the front call:
    • "ok" : the user accepted the permission.
    • "rejected" : the user refused the permission.

Usage

The "askForPermission" front call opens a message box to let the end user confirm the access to a "dangerous" Android permission, in order to enable a risky feature of the mobile device for the current app.

Important: Starting with Android 6, permissions to access dangerous mobile functions are no longer asked during app installation: The app must ask the user for dangerous permissions when needed, by using the askForPermission front call.

The permissions parameter defines the Android permission to be asked. It must be a string representing one of the Android permission contants, as defined in Android's Manifest permissions, prefixed by the "android.permission." string. For example, the "android.permission.WRITE_EXTERNAL_STORAGE" string can be used to identify the permission to access the SDCARD storage unit.

Important: Specific Android permissions required by the app still need to be specified when building the app. However, it is not needed to specifiy Android permissions required for built-in front calls: For example, if the app code makes a choosePhoto front call, the GMA will implicitely ask the user and set the Android permission to access the photo gallery. For more details, see Android permissions.

The front call will raise a runtime exception if the permission identifier is not valid.

Example

The following code example asks the user to access the SDCARD, and handles the user choice:

DEFINE result STRING
CALL ui.Interface.frontCall(
        "android", "askForPermission", 
        ["android.permission.WRITE_EXTERNAL_STORAGE"],
        [result] )
CASE result
   WHEN "ok"
      CALL os.Path.mkDir("/sdcard/myfiles")
   WHEN "rejected"
      ERROR "SDCARD access was denied by user"
END CASE