2017-02-24 108 views

回答

0

這個SO question描述了讀取和寫入日曆。關鍵的信息,你需要閱讀日曆(S)爲:

Uri uri = CalendarContract.Calendars.CONTENT_URI; 
String[] projection = new String[] { 
    CalendarContract.Calendars._ID, 
    CalendarContract.Calendars.ACCOUNT_NAME, 
    CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, 
    CalendarContract.Calendars.NAME, 
    CalendarContract.Calendars.CALENDAR_COLOR 
}; 

Cursor calendarCursor = managedQuery(uri, projection, null, null, null); 

然後,你需要從遊標提取數據:

ArrayList<String> ids = new ArrayList<String>(); 
try { 
     if (cursor.getCount() > 0) { 
      while (cursor.moveToNext()) { 
       String id= cursor.getString(0); 
       calendars.add(id); 
      } 
     } 
    } catch (AssertionError ex) { /*TODO: log exception and bail*/ } 

然後你的ID和需要查詢的每一個爲事件。這在SO question的接受答案中有所描述。此github存儲庫有一個解決方案。大多數這些方法僅適用於Android版本大於4.2的版本。

相關問題