qt_add_harmonyos_permission

Adds a HarmonyOS permission to the target executable.

The command is defined in the Core component of the Qt6 package, which can be loaded like so:

 find_package(Qt6 REQUIRED COMPONENTS Core)

This command was introduced in Qt 6.12.

Note: This command is in technology preview and may change in future releases.

Note: This command should only be called if targeting the HarmonyOS platform.

Synopsis

 qt_add_harmonyos_permission(target
     NAME <permission-name>
     [REASON <reason>]
     [USED_SCENE_ABILITIES <ability> [<ability>...]]
     [USED_SCENE_WHEN inuse | always]
 )

If versionless commands are disabled, use qt6_add_harmonyos_permission() instead. It supports the same set of arguments as this command.

Description

The command adds a HarmonyOS permission to the target executable. The permission is written into the requestPermissions array of the generated module.json5 manifest when the HAP package is built. Use this command to request additional permissions on top of the default permissions contributed by the Qt modules your application links against.

For the list of available permission names and their requirements, see the HarmonyOS application permission documentation.

Arguments

NAME is the permission identifier, for example ohos.permission.CAMERA. It is the only required argument.

REASON is the message shown to the user when the system prompts for a user_grant permission. It accepts either a literal string or a $string:<name> resource reference that resolves to a localized string from the application's resource files. Specifying REASON causes a usedScene block to be emitted for the permission.

USED_SCENE_ABILITIES is the list of abilities that use the permission. If omitted while a usedScene block is emitted, it defaults to QAbility, which is the single ability that hosts a Qt application.

USED_SCENE_WHEN sets when the permission is accessed. The accepted values are inuse (the permission is used only while the application is in the foreground) and always (the permission is also used in the background). If omitted while a usedScene block is emitted, it defaults to inuse.

Example

 qt_add_harmonyos_permission(myapp
     NAME ohos.permission.CAMERA
     REASON "$string:camera_permission_reason"
     USED_SCENE_WHEN inuse
 )
 qt_add_harmonyos_permission(myapp
     NAME ohos.permission.INTERNET
 )

See also Qt for HarmonyOS CMake API.