【问题标题】:Notification after a time一段时间后通知
【发布时间】:2013-08-02 00:34:42
【问题描述】:

我想添加一个 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);
    // ... 
}

【问题讨论】:

    标签: java android time notifications wait


    【解决方案1】:

    您需要将Alarm manager 与通知一起使用,以便在固定时间间隔后重复您的通知。检查 AlarmManagerNotificationManagerTutorialAndroid AlarmManager tutorialMultiple Notifications Using AlarmManager 。那里有很多教程。希望这可以帮助。

    【讨论】:

    • 我怎样才能只发出一个通知而不重复?现在它每 6 秒重复一次通知
    猜你喜欢
    • 1970-01-01
    • 2015-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2021-11-30
    • 1970-01-01
    相关资源
    最近更新 更多