0
我尝试在与我共享的日历上设置事件。我知道我应该使用日历的ID。但是我有问题。这里是我的代码:Android,如果共享日历获取ID
@OnClick(R.id.add_event_button)
public void addEvent() {
CalendarDB calendar = (CalendarDB) mCalendarSpinner.getSelectedItem();
Long id = calendar.getId();
ContentValues event = new ContentValues();
event.put("calendar_id", 1);
event.put(CalendarContract.Events.EVENT_TIMEZONE, "Europe/Berlin"); // Here choose your location time zone
event.put("title", "test application");
event.put("description", "This is test event");
event.put("eventLocation", "School");
event.put("dtstart", System.currentTimeMillis());
event.put("dtend", System.currentTimeMillis() + 1800 * 1000);
event.put("allDay", 0);
// status: 0~ tentative; 1~ confirmed; 2~ canceled
// event.put("eventStatus", 1);
event.put(CalendarContract.Events.CALENDAR_ID,8);
Uri l_eventUri;
if (Build.VERSION.SDK_INT >= 8) {
l_eventUri = Uri.parse("content://com.android.calendar/events");
} else {
l_eventUri = Uri.parse("content://calendar/events");
}
Uri l_uri = this.getContentResolver()
.insert(l_eventUri, event);
Toast.makeText(this, "SUCCESS", Toast.LENGTH_SHORT).show();
}
这一工程,并不过被添加的事件,日历的ID是未知的 - 我的意思是我尝试手动设置 - 1,2,3等,并弄明白上哪个日历事件将被添加。谷歌API网站说,ID应该是长的,当我得到日历列表时,我得到字符串作为id - 日历的名称。同样的情况在android.provider CalendarContract.class:
public static final String CALENDAR_ID = "calendar_id";
当我设置ID作为参数的应用程序崩溃 - 它需要长期争论。那么,如何获得共享日历的ID?预先感谢帮助:)