2

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 !

Herve B
  • 195
  • 1
  • 15

1 Answers1

3

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

Community
  • 1
  • 1
Chris
  • 3,329
  • 1
  • 30
  • 44
  • Thanks ! I'll try this out. But for the second solution, is there any way of sending a notification without using a library ? – Herve B Sep 25 '15 at 12:25
  • Yes there is, OneSignal has a faboulus interface for sending push notifications. You can design & sceduel messages to be send at a given time to a specific group, user or just to everybody. It also ( if you're looking for expanding your app to iOS ) can send push notifications to iOS device, making it a nice cross platform solution! Check it out! – Chris Sep 25 '15 at 12:27