Android的延迟通知 [英] Android Delayed Notification

查看:179
本文介绍了Android的延迟通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个使用Android的通知管理器一个通知,但诀窍是,我想要的通知显示30天以后。在我的code我这样做:

 意图notificationIntent =新的意图(这一点,MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(此,0,notificationIntent,0);
时长= System.currentTimeMillis的()+(30 * 24 * 3600 * 1000);
通知通知=新的通知(R.drawable.some_image,冠军的时候);
notification.setLatestEventInfo(getApplicationContext(),你迟到了,有些说明,contentIntent);
NotificationManager纳米=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
nm.notify(NOTIFY_ATTEND_ID,通知);
 

不过,该通知仍然显示瞬间。从我读,在何时参数来通知构造函数只用于在状态的通知进行排序。反正是有在未来某一日期/时间作出通知显示在?提前致谢。

解决方案
  

反正是有在未来某一日期/时间作出通知显示在?

没有。

由于Falmarri建议,您将需要处理这个自己,虽然我不同意他的做法。您将需要使用 AlarmManager 。不过,我怀疑 AlarmManager 工作30天工期,但你可以试试。您可能需要使用 AlarmManager 为每天/每周的任务,通过不同的报警来安排当天的/周的通知。您还需要重构这个名册报警上重新启动,因为他们得到消灭,因为Falmarri建议。

I am trying to create a Notification using Android's Notification Manager, however, the trick is that I want the notification to show up 30 days in the future. In my code I'm doing this:

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);

However, the notification is still showing up instantaneously. From what I read, the "when" parameter to the Notification constructor is only used to sort the notifications in the StatusBar. Is there anyway to make the notification show up in at a future date/time? Thanks in advance.

解决方案

Is there anyway to make the notification show up in at a future date/time?

No.

As Falmarri suggests, you will need to handle this yourself, though I disagree with his approach. You will need to use AlarmManager. However, I am skeptical that AlarmManager will work for 30-day durations, though you can try it. You may need to use AlarmManager for a daily/weekly task to schedule that day's/week's notifications via separate alarms. You will also need to reconstitute this roster of alarms on a reboot, since they get wiped, as Falmarri suggests.

这篇关于Android的延迟通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆