The idea is to send the user a notification every 24 hours.
The user has a list and when he clicks he will add an alarm.
If the current time is longer than the alarm time we will add 24 hours for it to just repeat on the next day and not immediately.
So far so good, the problem arises when the user changes the date to 1 day ago.
Let's suppose:
January 27 .
The user wants an alarm for 12:30 every day, if the current time is longer than these 12:30 will only give the alarm on January 28 , if the user walks back with the calendar for the day eg 10 January just start receiving notifications again on January 28.
Another problem is that if I put my calendar for 1 day to make sure and if the time is higher than the current one it immediately triggers the alarm.
I would like to know your opinion and if it is correct to set an alarm dependent on a click of the user, since it is no longer altered from that moment and then to solve the above errors should be changed.
And if you know a solution to this problem, I'd be grateful.
PendingIntent alarmIntent;
Intent intent = new Intent(HorariosActivity.this, AlarmReceiver.class);
intent.putExtra("id", favId);
alarmIntent = PendingIntent.getBroadcast(HorariosActivity.this, favId, intent, 0);
Calendar calendar = Calendar.getInstance();
long agora = calendar.getTimeInMillis();
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 30);
calendar.set(Calendar.SECOND, 00);
firstTime = calendar.getTimeInMillis();
if (agora > firstTime) {
calendar.add(Calendar.HOUR, 24);
firstTime = calendar.getTimeInMillis();
}
AlarmManager am = (AlarmManager) HorariosActivity.this.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, firstTime, 86100000, alarmIntent);