Android and specific notifications - android

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

Related

Notification scheduling

I am developing an android app which is about meal subsciption.
I update the entire menu(breakfast, lunch , dinner) for each day in the morning( I am using firebase).
Now i want to send scheduled notification to users that is, i want to notify a user at 1pm that this is the coming menu for the lunch similarly i want to notify the user at around 8pm that this is the coming menu of dinner.
What should i use to get this scheduled notification?
I had an idea in mind that when i update the database in the morning. I will send a data payload with the required scheduling time using cloud messanging and schedule the notification on the device itself.
Will this work?
Yes, it will work, I recommend using Worker to schedule notification and take into account receiving notifications while the app is in the background, because your app should have that feature I guess.

BroadcastReceiver active Observable vs single check up every 10min

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.

Confused about iOS notifications

I've read a lot about notifications in iOS now and I'm quite confused about how to reliably schedule notifications, actually. Let me explain my scenario:
I created an Android app that holds a fixed list of dates. The user can not add or remove dates, he can only view that list (garbage removal dates for my area). You can, however, configure that you want to be notified the day before. I've made that app so that when the device starts, a notification timer is started that fires at a certain time, checks whether there are pending items for the next day and if so, shows a notification. Then it re-schedules itself for the next day. So normally, the user doesn't need to open the app at all to receive notifications. He only opens the app once to configure his street, which triggers the first scheduled event, or to actually see the list of upcoming dates.
I'm now trying to port this app to iOS and I understand from what I've read that there's no way to replicate the way I'm doing stuff on Android. I understand that I can create up to 64 notifications for certain points of time in advance, but without the user opening the app at all I can not be sure to reliably schedule all the notifications I may need.
Is there a reliable way to simulate the described Android behavior? Or is there a way to force the user to open up the app once every 30 days or so?
In a nutshell no.
If applicable you can make notifications repeating, but if the dates are random and you can't repeat the notification then you can't schedule more than the limit.
You can't schedule your app to run and you can't force the user to do anything. All you can do is post some sort of notification for 30 days or whenever with some message that you hope will compel them to open your app.
If you have a valid use case for it in your app, you can enable a background mode such as a location change on a cell tower transition for example, then when your app runs in the background re-schedule the notifications. Or remote push, or background fetch etc. But even with background modes you cannot guarantee your app will actually run in the background, you can just help to increase the chances that it might and the different background modes have different degrees of usefulness in this sort of area.

ios alarm functionality limited?

I have an app which is on Android and iOS. I have added a local notification to fire every 24 hours at a time specified by the user of the app. In Android, the local notification functionality is exactly what I need, but in iOS it seems to lack the functionality I need, unless maybe I am missing something...
Lets say the user sets the time the notification is to fire to 11:00am. In Android, at 11AM, it will wake up the app, go to the broadcase receiver and I am able to run code in a method that calls out to an API to fetch the latest data. Once it gets the data, it posts the notification to the user.
In iOS, it seems the data being posted to the user has to be pre-scheduled. So I have to create the notification message during scheduling of the notification. What I need is to be able to do something more like the above example.
So the problem is that at the time of when the notification is scheduled to fire, I need to check for fresh data, not the day before...
Any suggestions?
The same functionality doesn't exactly exist on iOS.
You can setup a local notifications using the functionality of a UILocalNotification object. With this you can set fireDate, etc. which is sort of like a push notification without a server. You can send a message, add a badge on the app icon, play a sound, etc.
Now the issue is that the app doesn't get launched by the OS. The app simply registers a notification in the OS, which is then handled at the fireDate time. This means you won't be able to have a chance to check for data and verify whether to continue with the notification, etc.
UILocalNotification Class Reference

Android notify the user at a later time

I want to create an application in android in which the user selects a certain day in the future and then, when that day arrives he will get a notification (I know that this can be done through the Calendar or the notes but that doesn't matter in my case).
I have two problems concerting the previous:
a. How should I implement the notification ? I read elsewhere about adding events to the Google Calendar of the user - but that is not standard. Should I implement a service that checks to see if that day has arrived and add the notificatin ?
b. As I wrote, I care about day only, and not time. This generates the following problem for me: When should I notify the user in order to not bother him ? When the application knows only the day of the notification (and not the time) then how can it determine at what time in that day to actually notify the user ? What if the user is asleep ? Is it possible to add a "silent" notification so that the user won't be bothered ?
TIA,
Serafeim
Both problems are solved by a 'status bar notification'
http://developer.android.com/guide/topics/ui/notifiers/notifications.html
You can add a sound to this to alert the user.
If the user is 'asleep' i.e. the phone is on silent I believe the notification won't make a sound.
A notification does not need a time of day as you can 'notify' at the very start of the day and the user will see it when they first check there phone that day, so time is irrelevant.
You will have a service that runs to check the data yes, then start this notification. It may be possible to have an event listener for some given event that would start your service that would then check the date, and if so post your notification!
Here is my tutorial on this:
http://blog.blundellapps.com/notification-for-a-user-chosen-time/
Enjoy!

Categories

Resources