본문 바로가기
개발/안드로이드

[안드로이드]캘린더(calendar) 정보 가져오기

by darksilber 2011. 12. 12.
반응형

먼저 xml파일에 권한 등록
<USES-PERMISSION android:name="android.permission.READ_CALENDAR"></USES-PERMISSION>
 
public String getCalendar() {

StringBuilder cinfo = new StringBuilder();
Uri calendars = Uri.parse("content://com.android.calendar/events");

String[] projection = new String[] {
"calendar_id",
"htmlUri",
"title",
"eventLocation",
"description",
"eventStatus",
"selfAttendeeStatus",
"commentsUri",
"dtstart",
"dtend",
"eventTimezone",
"duration",
"allDay",
"visibility",
"transparency",
"hasAlarm",
"hasExtendedProperties",
"rrule",
"rdate",
"exrule",
"exdate",
"originalEvent",
"originalInstanceTime",
"originalAllDay",
"lastDate",
"hasAttendeeData",
"guestsCanModify",
"guestsCanInviteOthers",
"guestsCanSeeGuests",
"organizer",
"deleted"
} ;
Cursor managedCursor = getContentResolver().query(calendars, projection, "selected=1", null, null) ;
if(managedCursor.moveToFirst()) {
int[] calendar_id = new int[managedCursor.getCount()];

String[] htmlUri = new String[managedCursor.getCount()];
String[] title = new String[managedCursor.getCount()];
String[] eventLocation = new String[managedCursor.getCount()];
String[] description = new String[managedCursor.getCount()];
int[] eventStatus = new int[managedCursor.getCount()];
int[] selfAttendeeStatus = new int[managedCursor.getCount()];
String[] commentsUri = new String[managedCursor.getCount()];
int[] dtstart = new int[managedCursor.getCount()];
int[] dtend = new int[managedCursor.getCount()];
String[] eventTimezone = new String[managedCursor.getCount()];
String[] duration = new String[managedCursor.getCount()];
int[] allDay = new int[managedCursor.getCount()];
int[] visibility = new int[managedCursor.getCount()];
int[] transparency = new int[managedCursor.getCount()];
int[] hasAlarm = new int[managedCursor.getCount()];
int[] hasExtendedProperties = new int[managedCursor.getCount()];
String[] rrule = new String[managedCursor.getCount()];
String[] rdate = new String[managedCursor.getCount()];
String[] exrule = new String[managedCursor.getCount()];
String[] exdate = new String[managedCursor.getCount()];
String[] originalEvent = new String[managedCursor.getCount()];
int[] originalInstanceTime = new int[managedCursor.getCount()];
int[] originalAllDay = new int[managedCursor.getCount()];
int[] lastDate = new int[managedCursor.getCount()];
int[] hasAttendeeData = new int[managedCursor.getCount()];
int[] guestsCanModify = new int[managedCursor.getCount()];
int[] guestsCanInviteOthers = new int[managedCursor.getCount()];
int[] guestsCanSeeGuests = new int[managedCursor.getCount()];
String[] organizer = new String[managedCursor.getCount()];
int[] deleted = new int[managedCursor.getCount()];

for (int i = 0 ; i < title.length ; i++) {
cinfo.append("----------------------------------------------------");
calendar_id[i] = managedCursor.getInt(0);
htmlUri[i] = managedCursor.getString(1);
title[i] = managedCursor.getString(2);
if(title[i] != null)
cinfo.append("Title : "+title[i]+"\n");
else
cinfo.append("Title : "+"제목없음"+"\n");

eventLocation[i] = managedCursor.getString(3);
description[i] = managedCursor.getString(4);
if(description[i] != null)
cinfo.append("Title : "+description[i]+"\n");
else
cinfo.append("Title : "+"상세설명 없음"+"\n");
eventStatus[i] = managedCursor.getInt(5);
selfAttendeeStatus[i] = managedCursor.getInt(6);
commentsUri[i] = managedCursor.getString(7);

dtstart[i] = managedCursor.getInt(8);
dtend[i] = managedCursor.getInt(9);


eventTimezone[i] = managedCursor.getString(10);
duration[i] = managedCursor.getString(11);
allDay[i] = managedCursor.getInt(12);
visibility[i] = managedCursor.getInt(13);
transparency[i] = managedCursor.getInt(14);
hasAlarm[i] = managedCursor.getInt(15);
hasExtendedProperties[i] = managedCursor.getInt(16);
rrule[i] = managedCursor.getString(17);
rdate[i] = managedCursor.getString(18);
exrule[i] = managedCursor.getString(19);
exdate[i] = managedCursor.getString(20);
originalEvent[i] = managedCursor.getString(21);
originalInstanceTime[i] = managedCursor.getInt(22);
originalAllDay[i] = managedCursor.getInt(23);
lastDate[i] = managedCursor.getInt(24);
hasAttendeeData[i] = managedCursor.getInt(25);
guestsCanModify[i] = managedCursor.getInt(26);
guestsCanInviteOthers[i] = managedCursor.getInt(27);
guestsCanSeeGuests[i] = managedCursor.getInt(28);
organizer[i] = managedCursor.getString(29);
deleted[i] = managedCursor.getInt(30);
managedCursor.moveToNext() ;
}
}

managedCursor.close();

return cinfo.toString();
}

출처 - http://www.androidside.com/plugin/mobile/board.php?bo_table=B49&wr_id=53461

반응형

댓글