Androidã§GoogleCalendarã«ã¤ãã³ããç»é²ãã
GoogleCalendarã«ã¤ãã³ããç»é²ããæ¥æ¬èªçãªèª¬æããã¾ãã¿ãªãã£ãã®ã§æ¸ãã¦ã¿ãã
ãåæ¸ã
ãã¼ããã·ã§ã³ãå¿ããªãã
ã«ã¬ã³ãã¼æ å ±ãåå¾ããã
åå¾ããã«ã¬ã³ãã¼ã«ã¤ãã³ããç»é²ããã
éç¥æ å ±ãç»é²ããã
URIã«ã¤ãã¦
ãã¼ããã·ã§ã³ãå¿ããªãã
AndroidManifest.xmlã«å¿ããã«æ¸ãã¦ããã¾ãããã<uses-permission android:name="android.permission.READ_CALENDAR" /> <uses-permission android:name="android.permission.WRITE_CALENDAR" />
ã«ã¬ã³ãã¼æ å ±ãåå¾ããã
ã«ã¬ã³ãã¼ã«ã¤ãã³ããç»é²ããã«ã¯ãç»é²å
ã®ã«ã¬ã³ãã¼ãããããªããã°ã©ããããããªãã§ãã
ãªã®ã§ãã¾ãã¯ã«ã¬ã³ãã¼æ
å ±ãåå¾ãã¾ãã
String[] projection = new String[] { "_id", "name" };//idã¯ãã©ã¤ããªã¼ãã¼ãnameã¯ã«ã¬ã³ãã¼å String selection = "access_level" + "=?"; String[] selectionArgs = new String[] { "700" }; Uri calendarUri = Uri.parse(calendarProveName); Cursor managedCursor = managedQuery(URI.parce("content://com.android.calendar/calendars"), projection, selection, selectionArgs, null); int[] mCalIds; String[] mCalNames; if (managedCursor.moveToFirst()) { int len = managedCursor.getCount(); mCalIds = new int[len]; mCalNames = new String[len]; int idColumnIndex = managedCursor.getColumnIndex("_id"); int nameColumnIndex = managedCursor.getColumnIndex("name"); int i = 0; do { mCalIds[i] = managedCursor.getInt(idColumnIndex); mCalNames[i] = managedCursor.getString(nameColumnIndex); i++; } while (managedCursor.moveToNext()); }
selectionã§access_levelï¼ã«ã¬ã³ãã¼ã®ç·¨é権éï¼ãæ¡ä»¶ã«æå®ãã¦ãã¾ãã
"700"ã®å ´åããªã¼ãã¼æ¨©éã§ãã
ã¤ãã³ããç»é²ãããã®ã§ãªã¼ãã¼æ¨©éãããã«ã¬ã³ãã¼ã®ã¿ãåå¾ãã¦ãã¾ãã
ããã«ãããç¥æ¥ç¨ã®ã«ã¬ã³ãã¼ãªã©ãåå¾ãããªããªãã¾ãã
åå¾ããã«ã¬ã³ãã¼ã«ã¤ãã³ããç»é²ããã
ä¸è¨ã³ã¼ãã¯åå¾ããã«ã¬ã³ãã¼ã®1çªç®ã®ãã®ã«å¯¾ãã¦ç»é²ãã¦ãã¾ããContentResolver contentResolver = getContentResolver(); ContentValues cv = new ContentValues(); cv.put("calendar_id", mCalIds[0]); cv.put("title", "ã¤ãã³ãã®ã¿ã¤ãã«"); cv.put("description", "ã¤ãã³ãã®èª¬æ"); cv.put("eventLocation", "ä½æ"); cv.put("dtstart", startDate);//ããªç§ã§æå® cv.put("dtend", endDate);//ããªç§ã§æå® // éç¥æ©è½ã使ç¨ããå ´åã¯1ãè¨å®ããã使ç¨ããªãå ´åã¯çç¥ãã¦è¯ã cv.put("hasAlarm", mAlert); Uri eventUri = contentResolver.insert(Uri.parse("content://com.android.calendar/events"), cv);
ã¤ãã³ãã®æ å ±ã¯ã¾ã ä»ã«ãè¨å®ã§ãããã©çç¥ã
éç¥æ å ±ãç»é²ããã
éç¥æ©è½ã使ç¨ããªãå ´åã¯ãçç¥ãã¦è¯ãã§ããinsertã®æ»ãå¤ã®URIããä½æãããã¬ã³ã¼ãã®è¡çªå·ãåå¾ãè¨å®ãã¾ãã
long rowId = Long.parseLong(eventUri.getLastPathSegment()); cv.put("event_id", rowId); cv.put("method", 1);// éç¥æ¹æ³ãæå®ãã cv.put("minutes", time);//ååä½ã§æå®ãã contentResolver.insert(Uri.parse("content://com.android.calendar/reminders"), cv);
ããã§ã«ã¬ã³ãã¼ã«éç¥ä»ãã®ã¤ãã³ããç»é²ããã¾ãã
URIã«ã¤ãã¦
URIã®æå®ãAndroid2.2ã¨ãã以åã§éãã¾ãã- Android2.2
calendar :"content://com.android.calendar/calendars"
event :"content://com.android.calendar/events"
reminder:"content://com.android.calendar/reminders"
- Android2.1ã¾ã§
calendar :"content://calendar/calendars"
event :"content://calendar/events"
reminder:"content://calendar/reminders"
ãµã³ãã«
ä¸è¨URLã«ãµã³ãã«ã³ã¼ããç½®ãã¦ãã¾ãã
https://github.com/gensuke/SampleCalendar