Sending notification to everyone running an application, Android - java

Set up:
I have a system which has multiple users. Each user will download my app onto their Android phone and use it. What I want is when any user performs a specific action (I have two in my app), I want to pop up a notification in all the other user phones.
A simple break down is like this:
Start app --> Navigate to the part where action is performed --> Perform the action --> Store the action the a DB --> Notify ALL USERS --> Pop up the same notification on all phones.
How would I go about this problem? Can anyone suggest ideas or links, cause I don't even have a clue on how to approach this.

If you are looking to send notification to all users, even if all the users are not actively using the application, then Puch Notification is a good approach.
Push notifications let your application notify a user of new messages
or events even when the user is not actively using your application.
On Android devices, when a device receives a push notification, your
application's icon and a message appear in the status bar. When the
user taps the notification, they are sent to your application.
Notifications can be broadcast to all users, such as for a marketing
campaign, or sent to just a subset of users, to give personalized
information.
Have a look at Android Google Cloud Messaging
Also I have found XMPP a good solution as described by this post.
You will find some good solutions here and here

Well, you will need a database on a server, and then you will need the app to constantly (or at intervals) query the database in the background for changes, and notify the user when it finds one. A system similar to how many apps give notifications is what I am getting at.

Related

Best way to send firebase message or notification that trigger pull request from server

Currently the Android application I have taken in charge performs a "pull" on the server every minute to recover data and update a fragment with this data. Obviously this does not work when the device switches to doze mode. So I decided to use FCM as Google recommends.
Constraints :
The user needs to know that new data is available even in doze mode.
To not change the application too much, I do not want to send the data in the firebase message but rather send an https request to the server when I receive the fcm message.
The fcm message must:
Advise the user that new data is available with a notification.
If the user presses the notification OR returns to the application after turning the screen on, the https request must be triggered and fragment has to be updated.
I will add that it must be triggered at the latest when the user returns to the application.
My solution for now
I used a data message with a high priority instead of a notification message because a notification message need the user to tape the notification to trigger action.
In onMessageReceived :
I send the notification that redirects to my application.
I send my request to the server and update my application.
Disadvantage of my solution :
If my app is killed by the system while the screen was off what's going on?
My request has a time limit to complete when the phone come out of doze mode.
Questions :
Is this solution the best possible ?
Is there another way to proceed?
Perhaps could i schedule a task that runs immediately when user resume my app in onMessage received ? But i dont know how to do that.
Use WorkManager to schedule the background work to run immediately. It will also retry until your code indicates that it's successful.
I answer myself to close the subject and hope it can help someone !
After a night ... I definitely do not like the workmanager solution. Even if in practice it can work I do not like to use APIs for unplanned uses. If google tells me that it is not garanty to launch task immediately, they are (much :)) better than me and I believe them!
In this case, I think that my task may be postponed, for example because the OS wants to group calls with other apps. There may be internal conditions i dont know about.
Especially since I found a much simpler solution.
In onMessageReceived, I use a simple boolean indicator.
In the onResume of the activity I want to update I read this indicator and I launch my request if true for example.
I no longer need a scheduler, and after all if it is not done 100% reliable, it does not matter :
If fcm could send me a message there is a lot of chance there is a network when the user turn on the screen.
Even if there is none it is not very serious since I can warn the user who can proceed otherwise (by phoning for example !!!!)

How do whatsapp and instant messaging apps work in background without persistent notification in Oreo?

What I have studied on stackoverflow and Android documentation.
Finally I've concluded this:
There is no way to create a background service for continuous tasks. If I really want a service I should start a foreground service and user continuously sees a persistent notification "App is running". There is no way to hide this notification. It is intentionally added by Google.
Yes there are other options like WorkManager and JobScheduler but they do work periodically not continuously.
What I do want is to build an instant messaging app which continuously connects to the server using xmpp or sockets. But it requires a continuous connection but I don’t want to use a foreground service because it shows an irritating notification to the user "App is running".
Question 1: How does Whatsapp and other instant messaging app continuously connect to the server but not show a persistent notification ? How do they achieve this ?
Question 2: If Whatsapp use FCM for notifications then it will also work in those mobile which do not have playservices installed, so how does Whatsapp notification mechanism works ?
Starting with Android 6.0 (API level 23), Android introduces two power-saving features that extend battery life for users: DOZE and APP STANDBY. These two features enforce many restrictions on your background processing while the phone is in Doze mode. You should read about Doze and app standby in the following link
https://developer.android.com/training/monitoring-device-state/doze-standby
Now, about your use case is that you want to receive the messages and incoming calls even when the app is not running. For this use case, Android announced High Priority FCM messages in GoogleIO2016. They are high priority Push message which grant the application temporary wakelock and network access, independent of Device's Doze state or if the app happens to be in the app standby. This allows the application to react to the message and notify the user in whatever way it wants about the instant message or incoming call.
I don't know exactly how WhatsApp does that unless I look at their code but you can handle your use case using FCM High Priority Messages.
For more about your use case, follow the below link ofGoogleIO2016 Video from 08:30m to 10:30m
https://www.youtube.com/watch?v=VC2Hlb22mZM&t=505s
and read about this use case on the first link in this answer.

Save chat messages with closed app

Good evening!
I'm developing a chat application that looks like WhatsApp. I need the received messages to be saved on the user's mobile device. Until then everything was ok, because I was saving the messages when the user received the push notification on the mobile, but the problem happens when the application is closed because when the application is closed the push notification does not trigger the received push event (I am using the Onesignal to send the push).
I'd like to know how I can do this, ie get a notification and process it even with my closed application. I think it has to do this because Whatsapp does this and also Spotify also does it when I connect the Spotify to another device it automatically forces the opening of the application on my cell phone.
So my question is, how do I handle an event with the application closed or even force it to open according to a particular event?
I'm using the technology of Ionic 1 and Angular.js. For push notification I am using the OneSignal provider.
Thanks in advance for your attention and hope someone can help me. Thank you!
I'm fairly sure you won't be able to do what you're describing. There is a 'background push' feature introduced in iOS 9 that lets an app receive a payload triggered via push even when it is closed, but that's more for downloading (for example) a new edition of an online magazine, rather than lots of messages.
The difference betwen those two use cases is that if you're subscribed to a magazine, you might want the latest issue to download automatically whilst you have an internet connection, so that you have the issue to read when you're flying/on the train or whatever. A chat app... is pretty useless if you're not connected to the internet anyway, so there's no urgent need to have new messages 'pre-downloaded'
Even if you could do it, I don't think it would be best practice as there's too many scenarios where people won't have internet anyway so you're going to be left without the full message history when a user opens the app (not to mention push notification delivery is not tracked or guaranteed), so you're going to have to do some sort of query when the app launches to download new messages anyway.
If you've got code already that checks and downloads new messages while the app is open, that's great. But if its closed, you'll just need to run some sort of query on launch to download unread messages or something like that

Disable Google Calendar Push Notification when app is an owner of the change

When I create/update a Google Event from my app using java client:
events
.insert(originalCalendarId, googleEvent)
.setSupportsAttachments(true)
.execute()
I'm still getting push-notifications about event creation/update.
I don't want to get them since I'm the one who did these changes. The changes are applied on the app in a different way and additional push notifications are useless in this case.
However, I need to get new changes when they are made somewhere else(another app or Google Web UI).
Is there a way to handle this case? Maybe there is an approach to make Google know that push-notifications for specific queries aren't needed.
I also see that there is a property:
com.google.api.services.calendar.Calendar.Events.Insert#sendNotifications
But, no matter what I set here, notifications are still sent.
I think you have subscribed for a resource and you expect do not receive push notifications if your application have just done some changes. So you should use:
.insert(originalCalendarId, googleEvent)
.setSupportsAttachments(true)
.setSendNotifications(false)
.execute()
If you receive any way push notifications please check in your push notification X-Goog-Channel-ID with your own to be sure that is Google issue. I believe you have some old subscriptions that was not handled correctly and this is reason why do you receive the changes over push notifications.

Facebook notification when event happens on my server

I'm new to FB API, and I'm completely lost through variety of them. I have Java web app, and FB login to it on my site. How can I send notification to user, when some event happens (for example, his good arrived, and we want to notify him)?
Should I use Cavans application, or Graph API? Is it possible?
https://developers.facebook.com/docs/games/notifications
Currently, only apps on Facebook.com can use App Notifications. Notifications are only surfaced on the desktop version of Facebook.com.
Meaning, App Notifications are for Page Apps or Canvas Apps and you can send them with an App Access Token to every user who authorized your App. I suggest reading the whole article in the Facebook docs, there are some important rules and a lot of important information.

Categories