Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Add an event in Google Calendar from Activity?

I tried using content providers, but the event was not added to the calendar.

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);
like image 551
user851296 Avatar asked Jan 18 '12 17:01

user851296


1 Answers

Assuming you want to add an event to your users' calendar, the (unsupported) way of doing it on Android 2.x is described here.

As of Android 4.0, the practice changed while breaking support for the unsupported way as documented here. This was replaced by an official API working on ICS and onwards which is documented here.

like image 89
Morten Avatar answered Sep 28 '22 05:09

Morten