如何从“活动”在谷歌日历中添加事件



我尝试使用内容提供程序,但事件没有添加到日历中。

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);

假设你想在用户的日历中添加一个事件,这里描述了在Android2.x上(不支持)的方法。

从Android 4.0开始,这种做法发生了变化,同时打破了对此处所述不受支持方式的支持。这被一个官方的API所取代,该API致力于ICS及以后的工作,本文对此进行了记录。