-4

I want to send notification every day at the same time, saying "Good morning". I know create notifications for a specific day/hour, but for this case I do not know.

Wouva
  • 7
  • 2

1 Answers1

0

This answer solves the question using AlarmManager.

Intent myIntent = new Intent(Current.this , NotifyService.class);     
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
pendingIntent = PendingIntent.getService(ThisApp.this, 0, myIntent, 0);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 00);
calendar.set(Calendar.SECOND, 00);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY , pendingIntent);  //set repeating every 24 hours
Abhi
  • 3,431
  • 1
  • 17
  • 35
  • As @Abhi mentioned. use that code. In addition, pay attention to register to boot_completed as the alarm will not work after reboot – fbwnd Jun 29 '17 at 09:43