从SQLite DB设置Android通知 [英] Set android notifications from SQLite DB

查看:60
本文介绍了从SQLite DB设置Android通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个提醒应用程序,用户可以在其中将事件输入到SQLite数据库中.主屏幕列出了每个提醒的标题,单击一个项目将显示其详细信息.所有这些都很好.

I am building a reminder application where the user enters an event into an SQLite DB. The main screen lists the title of each reminder and clicking an item shows the details of it. All of this works fine.

现在,我想允许用户为每个项目设置通知,可以选择在活动预定前15分钟,30分钟或1小时设置提醒.

Now I want to allow the user to set up notifications for each item, being given an option to set a reminder for 15 mins, 30 mins, or 1hr before the event is scheduled.

我不知道如何进行此操作,也找不到任何好的教程.谁能给我一些有关如何实现这一点的想法?

I have no clue how to go about this and can't find any good tutorial on it. Can anyone give me some idea as to how I might implement this?

谢谢!

推荐答案

您将使用AlarmManager设置要在特定日期/时间触发的动作. (有很多关于如何使用AlarmManager的教程)

You'll use the AlarmManager to set the action to be triggered on the specific date/time. (there're A LOT of tutorials on how to use the AlarmManager)

警报管理器事件始终触发PendingIntent.根据此意图,您可以进行广播或启动服务. (您必须创建广播接收器或服务)

The alarm manager event always triggers a PendingIntent. From this intent you can either make a broadcast or start a service. (you'll have to create a broadcast receiver or a service)

然后在您建立的广播接收器或服务上显示通知.

Then on the broadcast receiver or service you build up and show the notification.

我建议使用广播接收器路由,它更干净,更无缝. 您还可能需要一个用于onBoot事件的广播接收器,以便在用户重新启动设备时在警报管理器上重新安排事件.

I suggest the broadcast receiver route, it's cleaner and more seamless. you might also to have a broadcast receiver for onBoot events to re-schedule the events on the alarm manager case the user reboots the device.

这篇关于从SQLite DB设置Android通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆