2012-01-18 148 views
10

我嘗試過使用內容提供程序,但該事件未添加到日曆中。如何在活動中添加Google日曆中的活動?

final ContentResolver cr = ctx.getContentResolver(); 

ContentValues cv = new ContentValues();  
cv.put("calendar_id", l_calId);  
cv.put("title", title);  
cv.put("description", description);  
cv.put("dtstart", millis1);  
cv.put("hasAlarm", 1); 
cv.put("dtend", millis2);  
cv.put("eventLocation", "Hall: "+location);  
cv.put("transparency", 1);  
cv.put("hasAlarm", 1);  


Uri newEvent ;  
if (Integer.parseInt(Build.VERSION.SDK) == 8)  
    newEvent = cr.insert(Uri.parse("content://com.android.calendar/events"), cv);  
else  
    newEvent = cr.insert(Uri.parse("content://com.android.calendar/events"), cv); 

回答

7

假設你想將事件添加到用戶的日曆,這樣做在Android 2.X的(不支持)的方式描述here

從Android 4.0開始,實踐發生了變化,同時打破了對here所記錄的不支持的方式的支持。這被替換爲在ICS上工作的官方API,並且其被記錄爲here