KNotifications

knotificationpermission.cpp
1/*
2 SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "knotificationpermission.h"
7#include <qnamespace.h>
8
9#ifdef Q_OS_ANDROID
10#include <QtCore/private/qandroidextras_p.h>
11
13{
14 if (QtAndroidPrivate::androidSdkVersion() < 33) {
15 return Qt::PermissionStatus::Granted;
16 }
17
18 return QtAndroidPrivate::checkPermission(QStringLiteral("android.permission.POST_NOTIFICATIONS")).result() == QtAndroidPrivate::PermissionResult::Authorized
19 ? Qt::PermissionStatus::Granted
20 : Qt::PermissionStatus::Denied;
21}
22
23void KNotificationPermission::requestPermission(QObject *context, const std::function<void(Qt::PermissionStatus)> &callback)
24{
25 if (QtAndroidPrivate::androidSdkVersion() < 33) {
26 callback(Qt::PermissionStatus::Granted);
27 }
28
29 QtAndroidPrivate::requestPermission(QStringLiteral("android.permission.POST_NOTIFICATIONS"))
30 .then(context, [callback, context](QtAndroidPrivate::PermissionResult res) {
32 context,
33 [res, callback]() {
34 callback(res == QtAndroidPrivate::PermissionResult::Authorized ? Qt::PermissionStatus::Granted : Qt::PermissionStatus::Denied);
35 },
37 });
38}
39
40#else
42{
43 return Qt::PermissionStatus::Granted;
44}
45
46void KNotificationPermission::requestPermission([[maybe_unused]] QObject *context, const std::function<void(Qt::PermissionStatus)> &callback)
47{
48 callback(Qt::PermissionStatus::Granted);
49}
50#endif
KNOTIFICATIONS_EXPORT void requestPermission(QObject *context, const std::function< void(Qt::PermissionStatus)> &callback)
Request notification permissions.
KNOTIFICATIONS_EXPORT Qt::PermissionStatus checkPermission()
Check if the current application has permissions to show notifications.
bool invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret)
QueuedConnection
PermissionStatus
QFuture< QtAndroidPrivate::PermissionResult > checkPermission(const QString &permission)
QFuture< QtAndroidPrivate::PermissionResult > requestPermission(const QString &permission)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:12:53 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.