Android 通知设置为 1 小时

Android notification set to 1 hour

我正在尝试显示推送通知以提醒用户检查他们选择的内容(洗碗、上班等)。对于初学者,我想将它设置为当前时间 + 1 小时。

但是我尝试了下面的代码,它没有改变任何东西(无论我设置什么值都会立即弹出通知)

 pushNotifAd.when = System.currentTimeMillis()+10000000;

这是完整的代码,请指导我如何在最初触发后 1 小时调用它:

//shows a notif on user tray, just pass the title and text!
public void pushNotif(String title,String text ){
    Context context = MainActivity.this
            .getApplicationContext();
    notificationManager = (NotificationManager) context
            .getSystemService(NOTIFICATION_SERVICE);

    pushNotifAd = new Notification();
    pushNotifAd.icon = R.drawable.icon;
    pushNotifAd.tickerText = "time to go to work!";
    pushNotifAd.when = System.currentTimeMillis()+3600000;//current time + 1 // hr in millisecs


    Uri uri = Uri.parse("work.com");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);

    notificationIntent = new Intent(Intent.ACTION_VIEW, uri);
    contentIntent = PendingIntent.getActivity(context, 0,
            notificationIntent, 0);


    pushNotifAd.setLatestEventInfo(context, "Go to work!",
            "Time to get stuff done!", contentIntent);

    notificationManager
            .notify(LIST_UPDATE_NOTIFICATION, pushNotifAd);

初始设置pushNotifAd.when=System.currentTimeMillis();然后 使用 getMinutesDifference 方法作为

if (getMinutesDifference(pushNotifAd.when, System.currentTimeMillis()) > 60) {
    // use notification method here
}

private long getMinutesDifference(long timeStart, long timeStop) {
    long diff = timeStop - timeStart;
    long diffMinutes = diff / (60 * 1000);
    return diffMinutes;
}