【发布时间】:2014-03-21 12:01:19
【问题描述】:
我在 android 日历中工作。我已经使用 android 应用程序以编程方式在日历中添加事件。 我也参考了这个链接:IllegalArgumentException: Unknown URL content://com.android.calendar/events when inserting an event to the calendar on Android Adding events to native calendar is not working 但在我的代码中不起作用。
我的代码是:
ContentValues contentEvent = new ContentValues();
// Particular Calendar in which we need to add Event
contentEvent.put("calendar_id", AlarmId);
// Title/Caption of the Event
contentEvent.put("title", "Wedding");
// Description of the Event
contentEvent.put("description", "Wedding Party");
// Venue/Location of the Event
contentEvent.put("eventLocation", "New York");
// Start Date of the Event with Time
contentEvent.put("dtstart", l);
// End Date of the Event with Time
contentEvent.put("dtend", l+60*1000);
// All Day Event
contentEvent.put("allDay", 1);
// Set alarm for this Event
contentEvent.put("hasAlarm",1);
contentEvent.put("eventTimezone", android.text.format.Time.getCurrentTimezone());
Uri eventsUri = getCalendarURI(false);
// event is added successfully
getContentResolver().insert(eventsUri, contentEvent);
// Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
public Uri getCalendarURI(boolean eventUri) {
Uri calendarURI = null;
if (android.os.Build.VERSION.SDK_INT <= 7) {
calendarURI = (eventUri) ? Uri.parse("content://calendar/events")
: Uri.parse("content://calendar/calendars");
} else {
calendarURI = (eventUri) ? Uri
.parse("content://com.android.calendar/events") : Uri
.parse("content://com.android.calendar/calendars");
}
return calendarURI;
}
我的问题是:当我运行我的应用程序时,该错误已生成。那么我该如何解决这个错误呢?
错误是:
java.lang.IllegalArgumentException: Unknown URL content://com.android.calendar/
提前谢谢你
【问题讨论】: