1
The idea is to send a notification to the user every 24 hours.
User has a list and when click will add an alarm.
If the current time is longer than the time of the alarm we will add 24 hours for it to repeat only in the next day and not immediately.
So far all well the problem arises when the user changes the date to 1 day ago.
Say :
Day 27 of January.
The user wants an alarm for 12:30 every day, in case the current time is longer than this 12:30 will only give the alarm in the day 28 January, if the user walks back with the calendar for the day for example January 10 only starts receiving notifications again on January 28.
Another problem is also that if I set my calendar for 1 day and if the time is longer than the current one triggers immediately 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, because it from that time is never changed and maybe to solve the above errors should be changed .
And if you can find a solution to this problem,.
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);
Tiago, when you refer to the user changing the date, do you refer to the Android date or the alarm date? Let’s take your example, when you say walk back on the date January 10th, you mean which of the two?
– Vitor Henrique
Change android date
– Tiago Coelho