As we know, developing on Android we can handle push notification and show a custom view depending on our logic. But there is a problem, if I send a push notification with a content and title from the server android will auto-display the notification and if I handle them at the same time the phone shows both, mine and the auto-displayed.
How can I disable auto display of the notification in these cases.
Why do I need to do this?
I am using OneSignal to send push notifications for both android and ios. The second one need to receive a content and title to be shown but this is not mandatory for android and I want to be able to show a custom view in this case.
Thanks in advance
You can omit the displaying of the OneSignal notification by the SDK by setting up a NotificationExtenderService per the OneSignal Background Data and Notification Overriding documentation. Use the NotificationExtenderBareBonesExample class example shown in step 2 and return true instead of false to let the SDK know your handling the notification.
Related
I am making a chat application and I am using Firebase Cloud Messaging to send push notifications. Everything is working fine but I do not want to display notification if the app is already in chat screen. I am using jetpack compose for UI and have single-activity architecture.
So in my chat screen, I don't want to display the notification. However, if the user is at other screens, I want to display the notification.
How can I achieve this?
There can be two possible solutions
Declare boolean in Activity or SharedPreference and toggle value according to lifecycle event's.
Once you receive firebase notification send broadcast and listen in activity. Inside activity identify top most visible screen using navController like below and decide wheather to show notification or not.
val visibleScreenRoute = parentNavController.currentBackStackEntry?.destination?.route?.split(Constants.KEY_QUESTION_MARK)?.getOrNull(0)
Hope this will help you to solve the issue.
I have the same case as you.
First, you need to create a custom notification and control push notifications manually.
Second, you have a module which checks whether activity is displaying or not.
Finally, when you receive notification data from firebase, using above module to decide display notification or not.
Check this document for more details : Build Notification
We want to send push notifications in Android and iOS to a group of users that match a certain condition. We can check if an user match this condition calling an API.
Our problem is that the users information changes very quickly and we don't have any way to keep track of this in our push notifications engine (OneSignal).
The only alternative we can think is to send the push notification to all users and client side call the API to get the latest user information. Depending on this we could choose to show the notification or ignore it.
Is this possible on Android and iOS?
It is 100% possible for sure. in the receiver class you call an intentservice, which can hit an api and get the latest information, based on the information you create notification using notification builder, and avoid if you dont want.
Yes, with the help of NotificationExtenderService this is possible.
Receive a notification in the background. Notification data is wrapped up in OSNotificationReceivedResult object. Now, read the notification id/title which should be unique for every notification.
Send this unique notification title/id along with user id to an API, which will return whether to show the notification to the user or not. If true then read notification title and message/description from OSNotificationReceivedResult and make a notification via NotificationCompat otherwise just ignore it.
Reference
This is the first time I am integrating notifications into my application. I am using Firebase. Setup was extremely simple and I am able to view the notification in the tray.
So, when the application is open, and if it receives a notification. I would like to display the notification in the activity itself.
How should I go about this?
You can look at Gmail approach. If there is new mail in current thread, they show SnackBar with notification.
You need to determinate connected parts of your app. And if notification connected to part where current user is - show SnackBar, and if there is something completely different - show heads-up notification.
Guide how to do Heads-Up notifications here
Guide how to do SnackBar notifications here
Have you ever tried Pushbots , its an infra- Structure for Notifications , it has more interesting Features than Firebase. Give it a shot.
Pushbots link
I'm using Parse to send push messages to my app. In some cases I want to show a notification however in some cases I don't. For example when data should be updated I intend to send a notification to all devices so that way they don't have to poll. This should not show any notification.
Parse's GcmBroadcastReceiver seems to always generate a notification without any way of turning that off.
I'm also curious of how to stop Parse from auto-creating a notification because at some point I'm going to want to work with more complex notifications, which Parse doesn't support.
I've tried creating my own GcmBroadcastReceiver however when I did that I didn't receive anything. Maybe I rigged it wrong? Other than that how can I stop Parse SDK from auto-generating a notification?
Omit alert and title from your push notification and the parse.com android SDK will not create a notification.
My intention is to display a notification with a personalised icon. However, if a notification with the same id is already displayed and then I need to add a new notification with the same id, my program will instead prepare a "stacked" version of the notification where the icon is changed to some generic icon and the notification content shows excerpts from the last and current notifications. Similar to how Gmail does when there are multiple emails.
To implement that I need to check if there are notifications of my app, currently displayed. I do not see any API to retrieve my own notifications.
I cannot simply cache the notification details that I have displayed till now, since in that case I need to know when they will be dismissed by the user, and update my cache accordingly. I also do not see any API to listen for dismiss events.
If you observe the gmail app notification behaviour properly u will notice that even when u dismiss one notification gmail shows you the same notification again in the list when a new notification comes. It looks to me that gmail is relying on total unread/unopened messages rather than keeping a cache of notifications.
There is no direct api for ur suggested SDK version. You need to fallback to ur own implementation. However, there is a way to know if a already showed notification was dismissed - How to know when my notification is cleared via Clear button?
This is possible with android 4.3 upwards now
See http://developer.android.com/reference/android/service/notification/NotificationListenerService.html#getActiveNotifications()