我已经设置了在特定时间出现在状态栏中的通知。当您按下它时,它会将“是”记录到数据库中。但是,如果 2 小时后没有按下它,我希望它记录“否”。我了解如何进行日志记录部分,但如果没有在两小时内按下,我不知道如何调用该场景。我知道我可以创建两个日历来比较它们,但是我又会把它们放在哪里呢?请问有什么建议吗?我在下面添加了一些代码。谢谢!
设置报警代码:
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);
通知代码:
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);