如何在Android中设置提醒?
我正在尝试为 Android 构建一个日历应用程序。我被夹在中间。我已设法从用户那里检索时间和任务等信息。
我不知道如何将其添加到 android 事件中。有类似 setEvent
或类似的东西吗?
I am trying to build a calendar app for Android. I am struck in the middle. I have managed to retrieve the information such as time and task from the user.
I don't know how to add this into android events. Is there anything like setEvent
or something similar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,如果您想将其透明地添加到用户的日历中,它比仅仅调用方法更复杂。
你有几个选择;
调用在日历上添加事件的意图
这将弹出日历应用程序并让用户添加事件。您可以传递一些参数来预填充字段:
或更复杂的:
使用此方法获取对日历的引用
(强烈建议不要使用此方法,因为它可能会在较新的 Android 版本上崩溃):
并以这种方式添加事件和提醒:
您还需要将这些权限添加到此方法的清单中:
更新:ICS 问题
上述示例使用未记录的日历 API,已针对 ICS 发布了新的公共日历 API ,因此出于这个原因,要针对新的 Android 版本,您应该使用 CalendarContract。
有关此内容的更多信息,请访问此博文。
Nope, it is more complicated than just calling a method, if you want to transparently add it into the user's calendar.
You've got a couple of choices;
Calling the intent to add an event on the calendar
This will pop up the Calendar application and let the user add the event. You can pass some parameters to prepopulate fields:
Or the more complicated one:
Get a reference to the calendar with this method
(It is highly recommended not to use this method, because it could break on newer Android versions):
and add an event and a reminder this way:
You'll also need to add these permissions to your manifest for this method:
Update: ICS Issues
The above examples use the undocumented Calendar APIs, new public Calendar APIs have been released for ICS, so for this reason, to target new android versions you should use CalendarContract.
More infos about this can be found at this blog post.
您可以将 AlarmManager 与通知机制结合使用
像这样:
它开始报警。
You can use AlarmManager in coop with notification mechanism
Something like this:
It starts alarm.
Android 完整源代码,用于添加具有开始和结束时间格式的事件和提醒。
向您的清单文件添加权限。
Android complete source code for adding events and reminders with start and end time format.
Add permission to your Manifest file.