Android 4.0에서는 캘린더가 Android 2.3과 동일한 Uri에 있습니다. 그래서 나는 다른 사람들이 같은 문제를 겪을 경우에 대비하여 코드를 첨부합니다.
public void addToCalendar(Context ctx, final String title, final String comment, final long dtstart, final long dtend) {
final ContentResolver cr = ctx.getContentResolver();
Cursor cursor ;
cursor = cr.query(Uri.parse("content://com.android.calendar/calendars"), new String[]{ "_id","calendar_displayName" }, null, null, null);
/*if (Integer.parseInt(Build.VERSION.SDK) == 8)
cursor = cr.query(Uri.parse("content://com.android.calendar/calendars"), new String[]{ "_id", "displayname" }, null, null, null);
*/
//Get all the calendar ids and name available in the phone
if (cursor.moveToFirst()) {
final String[] calNames = new String[cursor.getCount()];
final int[] calIds = new int[cursor.getCount()];
for (int i = 0; i < calNames.length; i++) {
calIds[i] = cursor.getInt(0);
calNames[i] = cursor.getString(1);
cursor.moveToNext();
}
//Creation of a new event in calendar whose position is 0 on the phone
ContentValues cv = new ContentValues();
cv.put("calendar_id", calIds[0]);
cv.put("title", title);
cv.put("dtstart", dtstart);
cv.put("dtend", dtend);
cv.put("eventTimezone","Spain");
cv.put("description", comment);
//Insertion on the events of the calendar
cr.insert(Uri.parse("content://com.android.calendar/events"), cv);
/*Uri newEvent ;
if (Integer.parseInt(Build.VERSION.SDK) == 8)
newEvent = cr.insert(Uri.parse("content://com.android.calendar/events"), cv);
*/
finish();
}
cursor.close();
}
존은 전에 말한대로 모든 정보가 http://developer.android.com/guide/topics/providers/calendar-provider.html입니다.
당신이 맞았습니다. 감사합니다;) 이벤트를 특정 캘린더에 추가하는 코드를 작성하려고합니다. 사실은 달력 테이블의 열 이름이 변경되었습니다. – ElChencho
내가 할 수있는 어떤 방식 으로든 도와 줘서 기뻐. –