我正在尝试使用 Android 的通知管理器创建通知,但是,诀窍是我希望通知在未来 30 天后显示。在我的代码中我正在这样做:
Intent notificationIntent = new Intent(this, MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
long when = System.currentTimeMillis() + (30 * 24 * 3600 * 1000);
Notification notification = new Notification(R.drawable.some_image, "A title", when);
notification.setLatestEventInfo(getApplicationContext(), "You're late", "Some description", contentIntent);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(NOTIFY_ATTEND_ID, notification);
但是,通知仍然会立即显示。据我所知,通知构造函数的“when”参数仅用于对 StatusBar 中的通知进行排序。有没有办法让通知在未来的日期/时间显示?提前致谢。
有没有办法让通知在未来的日期/时间显示?
No.
正如法尔马里建议的那样,您需要自己处理这个问题,尽管我不同意他的方法。您将需要使用AlarmManager
。然而,我怀疑AlarmManager
有效期为 30 天,不过您可以尝试一下。您可能需要使用AlarmManager
对于每日/每周任务,通过单独的警报安排当天/每周的通知。您还需要在重新启动时重新构建警报名册,因为它们会被擦除,正如法尔马里建议的那样。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)