Jump to content

Qt for HarmonyOS/qtohosextras doc/AppPermissions Namespace

From Qt Wiki
Revision as of 05:15, 17 September 2026 by Shawn Luo (talk | contribs) (Drop manual breadcrumb, MediaWiki renders it automatically (QTFOROH-2307))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

AppPermissions Namespace

QtOhosExtras::AppPermissions

The AppPermissions namespace contains types used for checking and requesting application runtime permissions. More...

Header: #include <AppPermissions>
qmake: QT += ohosextras
Since: Qt 5.12.12

This namespace was introduced in Qt 5.12.12.

Classes

struct PermissionResult

Types

enum class Permission { ReadPasteboard, CustomScreenCapture, AccessBluetooth, ApproximatelyLocation, Location }

Detailed Description

 auto *appContext = QtOhosExtras::QOhosAppContext::instance();
 if (!appContext->isPermissionGranted(QtOhosExtras::AppPermissions::Permission::AccessBluetooth)) {
     QObject::connect(
         appContext, &QtOhosExtras::QOhosAppContext::permissionRequestResponseWithResultReceived,
         [](QtOhosExtras::AppPermissions::Permission permission,
            QtOhosExtras::AppPermissions::PermissionResult result) {
             if (result.permissionGranted) {
                 // start using the permission-protected feature ...
             }
         });
     appContext->requestPermissionFromUserIfNeeded(
         QtOhosExtras::AppPermissions::Permission::AccessBluetooth);
 }

See also QtOhosExtras::QOhosAppContext and QtOhosExtras::QOhosAbilityContext.

Classes

class PermissionResult

The PermissionResult struct holds the result of a runtime permission request. More...

Type Documentation

enum class AppPermissions::Permission

Enumerates runtime permissions that can be checked and requested via QOhosAppContext and QOhosAbilityContext.

Constant Value Description
QtOhosExtras::AppPermissions::Permission::ReadPasteboard 0 Read the pasteboard ("ohos.permission.READ_PASTEBOARD").
QtOhosExtras::AppPermissions::Permission::CustomScreenCapture 1 Capture the screen ("ohos.permission.CUSTOM_SCREEN_CAPTURE").
QtOhosExtras::AppPermissions::Permission::AccessBluetooth 2 Access Bluetooth ("ohos.permission.ACCESS_BLUETOOTH").
QtOhosExtras::AppPermissions::Permission::ApproximatelyLocation 3 Get the approximate device location ("ohos.permission.APPROXIMATELY_LOCATION").
QtOhosExtras::AppPermissions::Permission::Location 4 Get the precise device location ("ohos.permission.LOCATION").

This enum was introduced or modified in Qt 5.12.12.