I've set up a notification that appears in the status bar at a certain time. When you press it, it will log "yes" into a database. However I want it to log "no" if it is not pressed after 2 hours. I understand how to do the logging part, but I have no clues on how to invoke that scenario if not pressed within two hours. I know I can create two calendars to compare them, but again where would I put these? Any suggestions please? I've added some of my code below. Thanks!
Setting alarm code:
Intent intent_noti = new Intent(this,Nofi.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 12345, intent_noti,
PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), setTime,
pendingIntent);
Notification code:
Intent intent = new Intent(this, ScanActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification noti = new Notification.Builder(this)
.setContentTitle("MedScan")
.setContentText("2. You should take pills now")
.setSmallIcon(R.drawable.original)
.setContentIntent(pIntent)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(
NOTIFICATION_SERVICE);
noti.defaults |= Notification.DEFAULT_ALL;
// Hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(ID, noti);
You can pass deleteIntent
with your notification object that will be called if the user explicitly Clear
your Notification
So to achieve your goal you can do the following:
Notification
or hit Clear
and cancel the Alarm
no
in the database