一段时间后通知

时间:2013-08-02 00:34:43

标签: java android time notifications wait

我想添加一个应该在几毫秒后启动的Notificationmanager。 一切都在运行,但我仍然不知道如何在几周之后添加通知的时间?

public void test(){
    int icon = R.drawable.ic_launcher;
    CharSequence ticker ="ticker";
    long showAt =System.currentTimeMillis();
    Notification notification = new Notification(icon, ticker, showAt);activity/intent
    CharSequence notificationTitle = "test";
    CharSequence notificationMessage = "Test1";
    Intent intent = new Intent(this, Activity.class);
    PendingIntent objPendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    Context ctx = getApplicationContext();
    notification.setLatestEventInfo(ctx, notificationTitle, notificationMessage, objPendingIntent);
    final int notificationIdentifier = 101; //an unique number set by developer to identify a notification, using this notification can be updated/replaced
    NotificationManager notificationManager = (NotificationManager)
            getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notificationIdentifier, notification);
    // ... 
}

1 个答案:

答案 0 :(得分:1)

您需要使用Alarm manager通知,以便在定期时间间隔后重复通知。查看AlarmManagerNotificationManagerTutorialAndroid AlarmManager tutorialMultiple Notifications Using AlarmManager。有很多教程。希望这可以帮助。