2012-01-18 172 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