简体   繁体   English

为了使用这样的服务,根据时间来创建的通知(机器人)

[英]which kind of service to use in order to create a notification according to time (Android)

I have a database in which the user saves the things that he wants to do.In each thing he can set a date of expiration.the point is, I want to create a list(notification list) where the "things to do" that are going to expire will appear. 我有一个数据库,用户可以在其中保存他想做的事情。在每件事中,他都可以设置失效日期。要点是,我想创建一个列表(通知列表),其中“要做的事情”即将到期将出现。 for example the user wants to create a list with the things that are going to expire in two days. 例如,用户想要创建一个列表,其中包含将在两天内过期的内容。 I have used the IntentService and pass with the intent the time that the user selects each time but i get nothing. 我已经使用了IntentService并用意图传递用户每次选择的时间,但是我什么也没得到。 do I have to use service or bound service in this case? 在这种情况下我必须使用服务还是绑定服务? thank you in advance 先感谢您

you can use AlarmManager class to fire off events at given times and in these events you can use NotificationManager to trigger the notifications. 您可以使用AlarmManager类在给定时间触发事件,在这些事件中,您可以使用NotificationManager触发通知。

See alarm manager example here: Alarm Manager Example 请在此处查看警报管理器示例: 警报管理器示例

See notifications guide here: https://developer.android.com/guide/topics/ui/notifiers/notifications.html 请参阅以下通知指南: https : //developer.android.com/guide/topics/ui/notifiers/notifications.html

Use the AlarmManager technique as like,.. 使用AlarmManager技术,就像..

    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, yearFromDB);
    calendar.set(Calendar.MONTH, monthFromDB);
    calendar.set(Calendar.DAY_OF_MONTH, dateFromDB);
    calendar.set(Calendar.HOUR_OF_DAY, hourFromDB);
    calendar.set(Calendar.MINUTE, minuteFromDB);
    calendar.set(Calendar.SECOND, 0);

Use PendingIntent for the Wake up at the Specific time and perform this Task.. 在特定时间使用PendingIntent唤醒并执行此任务。

    alarmManager.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(), ObjPendingIntent);

You can get the to do list on the Particular Time, Read on the PendingIntents and Alarmmanager by the following links.. 您可以通过以下链接获取特定时间的待办事项列表,在PendingIntents和Alarmmanager上阅读。

http://developer.android.com/reference/android/app/PendingIntent.html http://developer.android.com/reference/android/app/PendingIntent.html

and

http://developer.android.com/reference/android/app/AlarmManager.html http://developer.android.com/reference/android/app/AlarmManager.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM