我已在某个时间设置状态栏中显示的通知。按下它时,它会将“是”记录到数据库中。但是如果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);
答案 0 :(得分:2)
如果用户明确deleteIntent
Clear
Notification
与您的通知对象一起传递
为了实现您的目标,您可以执行以下操作:
Notification
或点击Clear
并取消Alarm
no