本页面

qt_add_android_permission

向目标可执行文件添加一个 Android 权限。

该命令定义在Qt6 包的Core 组件中,可按如下方式加载:

find_package(Qt6 REQUIRED COMPONENTS Core)

该命令于 Qt 6.9 版本中引入。

注意: 使用此 API时, AndroidManifest.xml 文件中必须包含<!-- %%INSERT_PERMISSIONS --> 标签。有关此标签使用的更多信息,请参阅《Qt 权限与功能》

语法概述

qt_add_android_permission(target NAME <permission-name> [ATTRIBUTES <name1> <value1> ...])

如果禁用了无版本号的命令,请改用qt6_add_android_permission() 。它支持与该命令相同的参数集。

描述

该命令向target 可执行文件添加一个 Android 权限。这可用于定义额外权限,或覆盖 Qt 模块设置的默认权限。

有关定义 Android 权限的更多信息,请参阅《Qt 权限与功能》。

示例

qt_add_executable(myapp
    // ...
)
qt_add_android_permission(myapp
    NAME android.permission.BLUETOOTH_SCAN
    ATTRIBUTES
        minSdkVersion 31
        usesPermissionFlags neverForLocation
)
qt_add_android_permission(myapp
    NAME android.permission.ACCESS_COARSE_LOCATION
)

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.