Android show notification from app - android

I have application that needs to show notification in status bar.
I have to set time and date in my app, and on that time and date notification needs to be shown in status bar as somekind of reminder.
I've tried this tutorial, but scheduled event isn't triggered at all.
Is there a way to do this?

I suggest that you use AlarmManager in connection with a SQL database to handle notifications. You could use AlarmManager to schedule alarms which are fetched from your database. You should use a BroadcastReceiver to add alarms when the phone boots in order to handle the situation where the phone is rebooted by the user or system failure.
This howto explains how to use the AlarmManager.

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.

How to use Notification Manager to send messages weekly

I am making an application which will send popup messages in the notification bar of the user, these messages have them send agree to a date specified weekly depending on the day, for example every Monday of each week, as I do that in android eclipse? I need besides those messages arrive so the application is closed, now I have a database in sqlite with notifications have to do weekly. Thank You
You can setup an alarm which should fire up a IntentService who in turn will fire up the notification. In the Service you can consult DB in order to decide to set a notification or not.
All this is done not in Eclipse but using Android API.
Yes, after alarm in configured, it will act despite of application running.

How to display notification every week?

I want to create a notification for users to remind them to open my app, in case they haven't opened it for more than a week. How can this be accomplished if my app isn't opened?
You can use AlarmManager to schedule and run your notification code. http://developer.android.com/reference/android/app/AlarmManager.html
You can find a lot of tutorials e.g. http://code4reference.com/2012/07/tutorial-on-android-alarmmanager/
So when your app starts you should cancel previous alarm and schedule new alarm to now + one week. This way alarm will be called(and notification displayed) only if app was not opened for more than week
you can try implementing push notifcations. Here is an example from parse. Very easy. You can also do your own. Push Notification

I want open a dialog box containing message periodically to users of app

We want to send messages to app users either through notifications, dialog box or image opening up on their screen every 24 hours telling them that our app is running on their phone.
We were looking to use Notification builder but it has limitation that it only works for api 11 and above and half of all app installations today are for earlier api versions. We are trying to find out which would be the best way to go with this.
I'm not sure what "Notification builder" is, but you can certainly use Notification and NotificationManager in any API you want.
So, putting it all together, I would use AlarmManager to fire off an alarm every 24 hours. Set up this alarm when your application runs, and in a BroadcastReceiver which is configured to receive BOOT_COMPLETED. The BOOT_COMPLETED notification allows you to quietly restart the alarm if the device reboots.
The alarm triggers another BroadcastReceiver which puts the notification up. If the user selects the notification, then your application is launched. Mostly, the presence of the notification will be all the reminder your user will need.
My notes say that NotificationManager can pop a View up onto the screen, which could be a dialog. However, I think a simple icon in the status bar would be best, since you're just reminding the user that the application is present.
Oh, p.s., if your application is a service that's running in the background 24/7, then you should also remember to restart it in the BOOT_COMPLETED broadcast.

Display status bar notification from a BroadcastReceiver

I'm writing code to display notifications to the user at specific times (just like the Google Calendar app).
I hence created :
a BroadcastReceiver that listens to BOOT_COMPLETED, upon reception it sets an alarm in one minute in order to not overload the device when it is still loading stuff;
a BroadcastReceiver that listens to alarms: the first set one minute after BOOT_COMPLETED, and the next at the next appointment (like in Google Calendar)
So, typically:
BOOT_COMPLETED => launch alarm with a one minute delay
One minute later => the Receiver sets another alarm for the next appointment
Several minutes/hours/days later, the alarm goes off => the Receiver displays a status bar notification
Which means that the status bar notifications are launched from the BroadcastReceiver.
I have read in the doc that they should be launched from Activities or Services : https://developer.android.com/guide/topics/ui/notifiers/notifications.html#Basics
I'm asking for best practice here. Should I create a Service that will be launched by the BroadcastReceiver, and which only purpose will be to launch the status bar notification? My code is working, I just want to create clean code as suggested by Google.
You can add a Notification from a BroadcastReceiver, AFAIK. That should be fairly fast. If StrictMode complains about it, then it might be worth worrying about -- otherwise, you should be OK.

Categories

Resources