larpon / QtFirebase

An effort to bring Google's Firebase C++ API to Qt + QML
MIT License
284 stars 83 forks source link

Is it possible to send push notifications while the app is not open? #89

Closed daljit97 closed 5 years ago

daljit97 commented 6 years ago

So I would like to send a custom notification using Firebase (like for example an update in my app) so that when the user can click notification in order to open the app. With QtFirebase is this possible? Can an app receive notifications even when closed? Reading on the Firebase docs it seems possible, but I am not sure about QtFirebase.

rmallah commented 6 years ago

Hi Daljit ,

Definitely it is possible. As a matter of fact the notifications arrive in the notification tray only when the app is in background. If it is in foreground the app directly receives it and there is no notification generated in the tray or notification area.

It is also possible to "embed" a payload with the notification and extract it in the Qt App. which in turn can be used to open a specific landing "Page" in the App when the notification if clicked in the tray.

regds mallah.

On Sun, Aug 26, 2018 at 5:53 AM daljit97 notifications@github.com wrote:

So I would like to send a custom notification using Firebase (like for example an update in my app) so that when the user can click notification in order to open the app. With QtFirebase is this possible? Can an app receive notifications even when closed? Reading on the Firebase docs it seems possible, but I am not sure about QtFirebase.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Larpon/QtFirebase/issues/89, or mute the thread https://github.com/notifications/unsubscribe-auth/AHHZuWvNp41QviVMfWAmaAfPRcyV7YX6ks5uUeqVgaJpZM4WMlcr .

daljit97 commented 6 years ago

when the app is in background. @rmallah does that mean that a user can receive a notification even when the app is completely closed and not in the multitasking view (still open but in the background)?

rmallah commented 6 years ago

Hi Daljit , Yes The notifications are received by the Firebase Services that are independent of your App. Even if your app is completely closed the FireBase receives the notification based on fcm_token or any kind of targeting. The Firebase console provides a way to test all these. Using fcm_token to target the device is a easy way.

daljit97 commented 5 years ago

@rmallah one last question before I close this issue, how I can set up a custom icon for notifications received when the app is closed?

daljit97 commented 5 years ago

Ok I figured that the way to set up a custom icons is exactly the same as on Android Java and modify the manifest file(for Oreo you also need to configure Notification Channels).

larpon commented 5 years ago

@daljit97 I'm glad you finally got it working. Have you documented the process? If so you're more than welcome to leave it here for future users! (The custom icon part)

daljit97 commented 5 years ago

@Larpon sorry for the late reply. I mentioned my problem here on stackexchange Unable to change icon

The issue was that I was testing the application on Android 8.0 Oreo. From this version of Android, Google requires that application make use of Notification Channels and applications are required to create a default Notification Channel. So I added the following code to the main activity of my application in the onCreate method:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    // Create channel to show notifications.
    String channelId  = getString(R.string.default_notification_channel_id);
    String channelName = getString(R.string.default_notification_channel_name);
    NotificationManager notificationManager =
            getSystemService(NotificationManager.class);
    notificationManager.createNotificationChannel(new NotificationChannel(channelId,
            channelName, NotificationManager.IMPORTANCE_LOW));
}

Then added the default notification id in the manifest file:

<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id"/>