直接添加一个事件日历 [英] Add an event directly to the Calendar
本文介绍了直接添加一个事件日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想直接与此code添加一个事件:
I'm trying to add an event directly with this code:
// Construct event details
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
beginTime.set(2013, 3, 14, 7, 30);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(2013, 3, 14, 8, 45);
endMillis = endTime.getTimeInMillis();
// Insert Event
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.DTSTART, startMillis);
values.put(CalendarContract.Events.DTEND, endMillis);
values.put(CalendarContract.Events.TITLE, "Walk The Dog");
values.put(CalendarContract.Events.DESCRIPTION, "My dog is bored, so we're going on a really long walk!");
values.put(CalendarContract.Events.CALENDAR_ID, 3);
values.put("eventTimezone", "Europe/London");
Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
// Retrieve ID for new event
String eventID = uri.getLastPathSegment();
这code语法是否正确,但不向日历添加事件。
有什么问题?
和Eclipse说,
This code syntactically is correct, but does not add event to the Calendar. What is the problem? And Eclipse says that
String eventID = uri.getLastPathSegment();
不被使用。
推荐答案
检查是否具有 WRITE_CALENDAR
权限才能创建事件这样的。
Check you have the WRITE_CALENDAR
permission to be able to create event this way.
另外,你的样品中,确实没有使用 EVENTID
变量 - >你什么都不做吧
Also, in your sample, the eventID
variable is indeed not used -> you do nothing with it.
这篇关于直接添加一个事件日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文