Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Create a Reminder Notification

Tags:

I have referred many sites but still I am not able to create the notification(reminder or alarm) I don't know exactly how to create and work with it. Its to notify/remind user about task and also provide daily tips to the user.. I will be glad to have your help in doing so and how to code it too...

Regards:) Thanxs for your help in advance.

like image 522
Rushabh Avatar asked Aug 31 '12 02:08

Rushabh


People also ask

How do I set up Reminder notifications?

On your Android phone or tablet, say "Hey Google, open Assistant settings." Or, go to Assistant settings. Under "All settings," tap Reminders. Enter the reminder details.

How do I set Reminder notifications on my iPhone?

Open the Settings app, then tap [your name] > iCloud and turn on Reminders. Inside the Reminders app, you'll see all of your reminders on all of your Apple devices that are signed in to the same Apple ID.

Do iPhone Reminders have notifications?

When you create a scheduled task, Reminders will alert you with a notification on your iPhone or iPad at the time you set. Launch Reminders from the Home screen. Tap New Reminder. It's in the bottom left corner of the screen.


1 Answers

You need two things:

  • AlarmManager: to schedule your notification at a regular bases (daily, weekly,..).
  • Service: to launch your notification when the AlarmManager goes off.

Here is a basic example:

In your Activity:

Intent myIntent = new Intent(this , NotifyService.class);     
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, myIntent, 0);

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.AM_PM, Calendar.AM);
calendar.add(Calendar.DAY_OF_MONTH, 1);

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000*60*60*24 , pendingIntent);

This will trigger Alarm each day at midnight (12 am). You can change that if you want.

Now, create a Service NotifyService and put this code in its onCreate():

@Override
public void onCreate() {
    NotificationManager mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.notification_icon, "Notify Alarm strart", System.currentTimeMillis());
    Intent myIntent = new Intent(this , MyActivity.class);     
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
    notification.setLatestEventInfo(this, "Notify label", "Notify text", contentIntent);
    mNM.notify(NOTIFICATION, notification);
}

And this code will show the notification when the Alarm is received.

Good Luck!

like image 73
iTurki Avatar answered Sep 19 '22 03:09

iTurki