I'm trying to set up a notification service for my application that shows upcoming shifts for an employee in a workplace - when a new shift is added for an employee by his/her boss I want notification to pop up.
Now the question I have is what is the correct way to implement it. In my BroadcastReceiver should I just make an Observable that listens to the changes of a node in firestore constantly or I should not use any listeners and use jobscheduler and check every e.g 10min if any changes occured?
The appropriate way to implement this would be using PUSH firebase service. Then register for PUSH on application startup, and save your token to your backend that stores the shift information.
You will likely have an API that changes, adds, or removes shifts, that API should then use the appropriate PUSH token for all employees affected by the shift change and send a payload to the appropriate devices to do a refresh or show a notification icon to open, or whatever action you want to occur from this.
Polling is not a good option, that should be a last resort and a darn good reason to do it should be supplied as it is wasteful on battery and resources.
Related
I am using Firebase with OneSignal within an hybrid application (Android + JS with cordova app). In some cases the user may become offline and online while he is still using the application.
Note that you can't retrieve a push notification if you don't have connectivity.
So my question is, is it possible to retrieve a push notification if the another user sends a push notification while the first user is offline, and later on this first user retrieves the connectivity (As a delayed push notification)?
Thanks!
Internally, OneSignal uses Firebase Messaging Service, so the constraints should be looked for there.
Firebase has 2 types of pushes: notification messages and data messages. That matters if you want to show a notification straight when a push comes, or you'd like to do some additional processing beforehand.
Then, you can configure Firebase to store and resend every message up to 28 days. Of course, losing a network connection for some time does not prevent a message to arrive.
There is another limitation though: up to 100 messages can be stored per client. So, if there are more than a hundred, it's better to re-request the diff.
And then, when the device finally comes back to the network, you should decide if you'd like the notification to come immediately even if the app is already minimized or the device is sleeping. Here is a part about push priorities.
Finally, to be able to work with Firebase on this lower level, you may need to configure OneSignal accordingly. Here is an instruction telling how to work with the background notifications, if you need them.
I've thinking this for a while that how do android app really notify its users?
Like Messenger, Messenger usually notify a user by making a floating circular profile picture of the sender.
and like other games like Subway Surfers or Zombie Catchers,
in the case of subway Surfers and other apps it notify users, when they are updated or an event is going on,
but in the case of Zombie Catchers, it notifies the users when their slushies are ready to be sold. Or the drones found new zombies at the alloted time.
So my concern is that, how can i notify my users when they have a unread messages or there is an event coming? without using Firebase?
If you are not using Firebase then I guess you must be using SQLite in android. If you are using SQLite then in order to notify its users you must add a TRIGGER on the table so that whenever some value is inserted or updated you can create a Notification Builder or any sort of notification like a TOAST.
E.g:
A user wants to know unread messages, there would be a table consisting of the number of message that are not opened. Whenever the app is opened it checks whether there are any unread messages and if there are/is, you can notify the user.
Link on how to use Trigger in SQLite.
How to use TRIGGER in Android SQLite
Link to notification builder.
https://developer.android.com/reference/android/app/Notification.Builder.html
However if you want the notification to appear when your App is closed, then you must also add a Sticky Service in the manifest file which would check the database after some interval and you should be good.
But I would recommend using Firebase since it has Value event listener and child event listeners making your task much easier.
I have been reading many posts/articles/tutorials I can find about updating an active notification. I fear I may have a fundamental misunderstanding about how one may update an Android push notification.
So far: I can update an active notification based on its ID, and I haven't been able to get any results out of Builder.setGroup()
My problem: When I update an active (not dismissed) notification, I want to be able to get the text from the previous, active notification, parse and add the new notification text and update it.
I'm starting to think that this might not be possible without a local DB and that my approach to this problem is no good.
Is there a way to get the content of the last notification (or one with a specific ID)?
EDIT: It seems to me that many of the examples I have seen are grouping a number of notifications all at once rather than successively.
Example
This is an example of what I want to do. The scenario I'm imagining is like this:
The owner of the device gets a notification that he/she has a new message from 'Alex Faaborg'. (See image)
The notification is not dismissed by the device owner
Another notification regarding a new message from 'Jeff Chang' comes in
Get 'Alex Faarborg's' name from the first notification, and 'Jeff Chang' from the second
Parse the info and display a summary of their notifications rather than have multiple notifications build up
4 is what I'd like to do
OK, so I realized I could do what I need to do to combine notifications by keeping track of users' unread messages(or invites etc..) on the backend, then if there's more than one, it will send out a summary of the notifications rather than each individually. On the client, this will overwrite any previous, related notifications (kept track with a JSON field sent to GCM (and subsequently, the client) that represents the 'topic' of the notification)
For whatever reason, I thought I should handle the grouping/summarizing of notifications on the client. I think the API is the way to go.
I want my app to notify users of specific events that can occur at a certain time.
I know how to send a notification knowing the exact time of it, but things get a little complicated for me when I want to trigger notifications at times that are unknown at app install (notifications whose time can change or which depend on a specific event).
Here are two cases in which I don't know how to trigger a notification :
Send a notification every day at a time that can change from day to day. Say I want to notify users that it's sunrise time, do I need a Service to run permanetly an calculate for each day the time of sunset and trigger a notification when the time comes ?
Send a notification everytime something new in the community occurs. I don't want to notify users of an update, but just of a particular event at a certain time. How do I send notifications to them?
How can I achieve this ?
Thanks !
For your first option i would use a AlarmManager. It will execute a function on a specific time, that can be set on app startup. Everytime the AlarmManager executes and sends a notification to the user, it should re-calculate the next message time and reset the AlarmManager. ( see how to reset here )
For your second scenario you could use a library like OneSignal. It's a verry usefull library for registering users for pushnotifications and sending messages from a website to your users. You can choose groups of users or specific users for sending messages and you can customize the look of your pushmessages ( add buttons, images, .. etc).
I'm making an app that remind a close forum with something like 100 users. Every time a user is asking a question, the app needs to send notification for all the users that taking place in his close forum, that going to be a lot of notification that send Simultaneously.
Does anybody know what is the best way to set that kind of notification in android? Maybe every time the database is updating, or update the user app every 3 min. I need that the users will get the notification as soon as they can.
Thanks!
Notifications can be broadly put under two categories push notifications and pull notifications.
Push: This would require server action based on the event, check Google Cloud Messaging
Pull: Where you run a service on the device and keep on pinging the server after a certain interval for data.
In your scenario, if the notification required is not real-time you might want to go with Pull notification albeit with something like 10 minutes interval even more. Lesser the interval, more battery and data charges for the user. In case real-time notification is required you can go with Push.
If you have acces to web resource you can use GCM (Google Cloud Messaging, http://developer.android.com/google/gcm/index.html) to push messages to your android clients. So it will not drain so much power, as pulling mode.
If you have not, the best way is to retreive data by some interval and notify user about data changing. Also you can retreive only header Content-Length and compare with previous value to prevent for loading all page