diff options
Diffstat (limited to 'examples/corelib/platform/androidnotifier/notificationclient.cpp')
-rw-r--r-- | examples/corelib/platform/androidnotifier/notificationclient.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/examples/corelib/platform/androidnotifier/notificationclient.cpp b/examples/corelib/platform/androidnotifier/notificationclient.cpp index af1cb7322a..aa6093c29c 100644 --- a/examples/corelib/platform/androidnotifier/notificationclient.cpp +++ b/examples/corelib/platform/androidnotifier/notificationclient.cpp @@ -5,10 +5,22 @@ #include <QtCore/qjniobject.h> #include <QtCore/qcoreapplication.h> +#include <QtCore/private/qandroidextras_p.h> + +using namespace Qt::StringLiterals; NotificationClient::NotificationClient(QObject *parent) : QObject(parent) { + if (QNativeInterface::QAndroidApplication::sdkVersion() >= __ANDROID_API_T__) { + const auto notificationPermission = "android.permission.POST_NOTIFICATIONS"_L1; + auto requestResult = QtAndroidPrivate::requestPermission(notificationPermission); + if (requestResult.result() != QtAndroidPrivate::Authorized) { + qWarning() << "Failed to acquire permission to post notifications " + "(required for Android 13+)"; + } + } + connect(this, &NotificationClient::notificationChanged, this, &NotificationClient::updateAndroidNotification); } |