Show only notification with multi application when call push from server - android

I created two applications and installed them on a device. Both apps have the same notification id. Whenever I send a push notification from my service, two notification show up.
I want to show only one notification (instead of displaying the same notification twice). Can I do it? If so then how can I do it?

You can use a shared preferences between the two apps and write a value when some app show the notification. Then just before to show it you should check the shared preferences to know if the other application has shown the notification or not. Even you can add delay in one of the applications giving preference to the other one.

Related

How to control whether to display notification or not based on the screen that is being displayed in android studio?

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

Check if "setFullScreenIntent" leads to a launch of the application or to the display of a notification

I get a firebase notification and create a NotificationCompat.Builder with the "setFullScreenIntent" option. This leads to different behaviours on different systems or different device status.
Sometimes the app launches directly, sometimes a notification is displayed.
I have to surpress a ringtone if the user clicked on the notification but play it when the app starts directly.
How do I get to know which one happened when my activity starts?
Sorry for my English.
You can do cancel the Notification in activity#onCreate or other lifecycle where you want

Showing notification from server directly in app

Android push notification show notification in title bar.But i want notification to be directly shown in the app if the app is opened.For example in driving apps when customer request for cabs, notification is directly shown in the driver app which is opened.Driver don't need to refresh the app or click on any link.How can i do that?Should i use push notification only?
Its upto you how you want to use the data you get from the GCM.In a typical case you get the data from the GCM server which invoke your Broadcast receiver and which starts the service where you parse the data and then create a notification and show it.If you don't want to create a notification just parse the data and populate the view and show it wherever you want in the current activity or somewhere else.Its entirely upto you how you want to implement it,there are many ways to implement it

Handling Parse Push Notifications in Android

I am using Parse API in order to handle push notifications. In our Android application, I want to accomplish two things:
1) If we have received a Push Notification with the application is closed and the user clicks on the notification, I want to be able to understand that the application is being opened via a push notification.
2)If we receive a push notification while the application is open, I want to handle this and do some extra work.
In both cases, I want to be aware that the application has received a push notification in order to execute some special operations.
As far as I understand from Parse API documentations, it offers two methods of handling pushes: Responding with an Activity and Responding with an Intent. I am currently calling
PushService.setDefaultPushCallback(context, MainActivity.class);
in my Application class with needed changes in the AndroidManifest.xml file and already receive push notifications, this corresponds to Responding with an Activity method. But I don't know how to be aware of Push Notifications explicity with this method.
Thanks in advance.
When a push is received ,Check
1:Whether our application is in foreground or background.
If it is foreground, that means app is visible and do your stuff(show alerts or anything you want).
If app is in background,that means it is not visible and if you want to do any thing based on this.
i hope this helps..

In Android how do I get the currently displayed notification for a given notification id?

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()

Categories

Resources