Android Notification problem app close
-
wrote on 24 Nov 2016, 16:43 last edited by Djeff
I'm currently trying to set some notification using Qt 5.7 for Android. The notification work fine when the App is open and when the App is on the background, but the notification stop working when Android clear the RAM.
Here my code, notification.cpp
#include "notificationclient.h" #include <QDebug> #include <QtAndroidExtras/QAndroidJniObject> NotificationClient::NotificationClient(QObject *parent) : QObject(parent) { connect(this, SIGNAL(notificationChanged()), this, SLOT(updateAndroidNotification())); } void NotificationClient::setNotification(const QString ¬ification) { if (m_notification == notification) return; m_notification = notification; emit notificationChanged(); } QString NotificationClient::notification() const { return m_notification; } void NotificationClient::updateAndroidNotification() { QAndroidJniObject javaNotification = QAndroidJniObject::fromString(m_notification); QAndroidJniObject::callStaticMethod<void>("com/loayza/medit/NotificationClient", "notify", "(Ljava/lang/String;)V", javaNotification.object<jstring>()); }
notification.java :
package com.loayza.medit; import android.app.Notification; import android.app.NotificationManager; import android.content.Context; public class NotificationClient extends org.qtproject.qt5.android.bindings.QtActivity { private static NotificationManager m_notificationManager; private static Notification.Builder m_builder; private static NotificationClient m_instance; public NotificationClient() { m_instance = this; } public static void notify(String s) { if (m_notificationManager == null) { m_notificationManager = (NotificationManager)m_instance.getSystemService(Context.NOTIFICATION_SERVICE); m_builder = new Notification.Builder(m_instance); m_builder.setSmallIcon(R.drawable.iconnotif); m_builder.setContentTitle("Tratamiento !"); } m_builder.setContentText(s); m_notificationManager.notify(1, m_builder.build()); } }
What can I do to keep my App running on the background even after Android close it ?
Thanks for your help
1/1