Closed david-becher closed 5 years ago
Let me put it differently: suppose I have a app which features a messaging functionality. If a new message is posted, a notification via ibm bluemix is posted.
If the app is in the background, I want to have a Notification in the system tray (ideally, completely configured and designed by myself). When the user clicks the notification, it takes him not to the launcher activity, but directly to the message details activity.
If however the app is in the foreground while the notification comes in, I e.g. just want to display a pop up or snackbar. The user then can decide himself to go to the message details screen or stay at his current activity.
How would I approach that with the IBM Bluemix framework?
@dbecher-ito We don't support the data message.
But for this case , use the notificationListener method for handling the notification click.
OR
Use the setNotificationStatusListener.
Try using the actionable Notifications also for this requirement. Follow this for the action handling - https://github.com/ibm-bluemix-mobile-services/bms-clientsdk-android-push/tree/Doc#interactive-notifications
Hope this will help. Thanks
@AnanthaKrish thanks for your reply.
I understand that I have to use the notification listener. But basically I want to have different behaviors depending whether the notification is received when the app is in the background vs when the app is in the foreground.
To illustrate it with my example from above: Of course I can program the notificationHandler in a way, that if there is a message for my fictional push-based Mail application, that by clicking on the notification badge in the system tray, the detailed email message is downloaded and displayed. But if I am already using the App (the app is in the foreground), the same notification handler is triggered and the user gets the message displayed, even though he might be currently doing something more important, like composing a message. In the second case, I don’t want the same behavior like when clicking on the notification in the system tray, I just want to display a pop up.
I hope this explains my use case well. Could you elloborate on how this is possible with your library? Or how do I have to tweak it?
@dbecher-ito Hi,
So the scenario is,
First case - If the app is background or not running state, notification will come in the tray and when click on the notification it will go to the desired activity from the notificationHandler
, right ?
Second case- When the app is in the foreground , it should only show the popup , right ?
Correct me if I am wrong ...
Yes, indeed!
In addition for the first case: the desired activity is not the main launcher activity (I noticed that your code actually opens the main activity when the notification is clicked). However, even with the main activity first opened it would be no problem, because of course I can just startActivity
to open it right away.
Yes. Only some pop up or other means of communicating to the user that there is something new, but he should not be forced to be transitioned to the desired activity of the (1) case.
@dbecher-ito Give me sometime , I will get back to you .
@dbecher-ito Hi,
I got one solution,
setNotificationStatusListener
and notificationListener
methods.a. In the setNotificationStatusListener
, check whether the status is MFPPushNotificationStatus.RECEIVED
and app is in background . If yes then store the messageId in the sharedPreferences
. Else don't do anything
b. In the notificationListener
get the messageId from the additional payload (that is nid
, you can get it by converting additional payload into JsonObject). Then check for the messageId in the sharedPreferences
. If its there handle open the new activity. If its null, that means the app is in the foreground, so you can show a popup .
Nevertheless there is a problem here , if the app was not in the background (not in running state), it will not call the setNotificationStatusListener
, so you have to add some action button on the popup , that will handle the actions you want (i.e.: going to another activity or staying in the current page). This same implementation needed if message is deleted from the tray.
Let me know If you have any doubts. Meanwhile I will look for a better solution.
Hey there,
Androids firebase differentiates between notification messages and data messages.
I used this https://mobile.eu-gb.bluemix.net/imfpush/#!/messages/post_apps_applicationId_messages swagger API to send test push notifications, however I recognized that it seems to be only possible to send notification messages with an optional payload? What about data only messages?
The advantage of data only messages is, that they never get dispatched to the system tray of android, even if the app is in the background.
I need this because I want to handle messages in the callback, but I always want to decide myself whether notifications get shown in the system tray. And I also want to be able to customize the Intent of the system tray notifications.
Basically I want to have different handling behaviors whether the app is in the foreground or in the backgroud when push messages arrive.
Do you have any recommendations?