/* SPDX-FileCopyrightText: 2023 Volker Krause SPDX-License-Identifier: LGPL-2.0-or-later */ #include "knotificationpermission.h" #include #ifdef Q_OS_ANDROID #include Qt::PermissionStatus KNotificationPermission::checkPermission() { if (QtAndroidPrivate::androidSdkVersion() < 33) { return Qt::PermissionStatus::Granted; } return QtAndroidPrivate::checkPermission(QStringLiteral("android.permission.POST_NOTIFICATIONS")).result() == QtAndroidPrivate::PermissionResult::Authorized ? Qt::PermissionStatus::Granted : Qt::PermissionStatus::Denied; } void KNotificationPermission::requestPermission(QObject *context, const std::function &callback) { if (QtAndroidPrivate::androidSdkVersion() < 33) { callback(Qt::PermissionStatus::Granted); } QtAndroidPrivate::requestPermission(QStringLiteral("android.permission.POST_NOTIFICATIONS")) .then(context, [callback, context](QtAndroidPrivate::PermissionResult res) { QMetaObject::invokeMethod( context, [res, callback]() { callback(res == QtAndroidPrivate::PermissionResult::Authorized ? Qt::PermissionStatus::Granted : Qt::PermissionStatus::Denied); }, Qt::QueuedConnection); }); } #else Qt::PermissionStatus KNotificationPermission::checkPermission() { return Qt::PermissionStatus::Granted; } void KNotificationPermission::requestPermission([[maybe_unused]] QObject *context, const std::function &callback) { callback(Qt::PermissionStatus::Granted); } #endif