java - 一段时间后通知

标签 java android time notifications wait

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

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);
    // ... 
}

最佳答案

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

关于java - 一段时间后通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18006921/

相关文章:

java - 数字的正则表达式

android - 如何在 React Native-App 中从 res/drawable-folder 加载图像?

PHP 错误的日期/时间

javascript - 有什么方法可以从网站获取智能手机号码吗?

安卓多设备开发

Java 日期时间差异

python - 使用 pandas 添加数据框列中缺失的时间

java - 如何通过 Apache POI 使用公式从 Excel 检索日期

java - 将外部库的源代码和Javadoc添加到Eclipse/Gradle

java - 带LinkedHashMap的多维字节数组……还有更好的办法吗?