0

我有这个添加事件的代码:

Intent calendarIntent = new Intent(Intent.ACTION_INSERT, Events.CONTENT_URI);

Calendar beginTime = Calendar.getInstance();
beginTime.set(2013,04,14,21,00,00);

Calendar endTime = Calendar.getInstance();
endTime.set(2013,04,14,21,10,00);
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("title", "Some title");
intent.putExtra("description", "Some description");
intent.putExtra("beginTime", beginTime.getTimeInMillis());
intent.putExtra("endTime", endTime.getTimeInMillis());
startActivity(intent);

但是如何在不打开日历的情况下插入事件?

谢谢

4

1 回答 1

1

你需要使用 aContentResolver代替Intent

ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();

Calendar beginTime = Calendar.getInstance();
beginTime.set(2013,04,14,21,00,00);

Calendar endTime = Calendar.getInstance();
endTime.set(2013,04,14,21,10,00);

values.put(Events.DTSTART, beginTime.getTimeInMillis());
values.put(Events.DTEND, endTime.getTimeInMillis());
values.put(Events.TITLE, "Some title");
values.put(Events.DESCRIPTION, "Some description");

Uri uri = cr.insert(Events.CONTENT_URI, values);

你可以阅读更多日历提供者

于 2013-04-14T18:07:10.793 回答