Name
PermissionRequest -- request permission from user (V8.0)
Synopsis
ok = PermissionRequest(perms)
Library
requester

Platforms
Android only

Function
This function can be used to request certain permissions from the user. Due to security reasons, Android apps need first ask for user permission before they will be able to execute certain actions. This function can be used to request such permissions from the user. Android will then show a dialog box in which the user can either accept or decline the permissions. If he declines, PermissionRequest() will return False, otherwise True will be returned.

The permissions you want to request have to be passed in the perms argument. This can be set to one of the following permission flags:

#PERMREQ_READEXTERNAL:
If your app has this permission, it will be able to read files from the external storage device. The external storage device can be accessed through the SDCard item in the table returned by GetSystemInfo(). By default, Android apps are not allowed to read from the external storage device. Note that this flag is only supported on Android versions older than version 11. If you need access to the external storage on Android 11 and up, you should use the new #PERMREQ_MANAGEEXTERNAL flag instead (see below).

#PERMREQ_WRITEEXTERNAL:
If your app has this permission, it will be able to write and read files to/from the external storage device. The external storage device can be accessed through the SDCard item in the table returned by GetSystemInfo(). By default, Android apps are not allowed to write to the external storage device. Note that #PERMREQ_WRITEEXTERNAL implies #PERMREQ_READEXTERNAL so you don't have to set #PERMREQ_READEXTERNAL when using this flag. Also note that this flag is only supported on Android versions older than version 11. If you need access to the external storage on Android 11 and up, you should use the new #PERMREQ_MANAGEEXTERNAL flag instead (see below).

#PERMREQ_MANAGEEXTERNAL:
If your app has this permission, it will be able to write and read files to/from the external storage device. The external storage device can be accessed through the SDCard item in the table returned by GetSystemInfo(). By default, Android apps are not allowed to write to the external storage device. This is the recommended way to ask for full read/write permission on the external storage device for all systems running Android 11 and higher. Keep in mind that due to security concerns Google imposes severe restrictions for apps requiring full access to the external storage device so if your app requests this permission, it might not be allowed on the Play Store. If you intend to publish your app on the Play Store, it's recommended to use Android's Storage Access Framework (SAF) or MediaStore instead of requesting the #PERMREQ_MANAGEEXTERNAL permission. See Working with Android URIs for details. (V11.0)

Note that this function is only needed when compiling stand-alone APKs using the Hollywood APK Compiler. When using the Hollywood Player, the Hollywood Player will automatically request the #PERMREQ_WRITEEXTERNAL permission (on pre-Android 11 systems) or the #PERMREQ_MANAGEEXTERNAL (on Android 11 and higher) for you so you don't have to do that manually and your applets will automatically be able to access the external storage.

Inputs
perms
permission to request (see above for possible values)
Results
ok
True if user granted permission, False if he declined them
Example
If PermissionRequest(#PERMREQ_WRITEEXTERNAL)
  t = GetSystemInfo()
  StringToFile("Hello World", FullPath(t.SDCard, "test.txt"))
Else
  NPrint("Sorry, no permission!")
EndIf
The code above tries to get a permission from the user to write to the external storage device. If the user grants this permission, the code will write a file named test.txt to the external storage device.

Show TOC