I need to be able to create an event in the Google Calendar from my Android app. I believe there is a Calendar API but I have never used it. I'm fairly new to Android development so I've found a few examples from browsing earlier and used the following code to try to update my Android Calendar.
public static boolean updateCalendar(Context context,String cal_Id,String eventId)
{
try{
Uri CALENDAR_URI = Uri.parse(CAL_URI+"events");
Cursor c = context.getContentResolver().query(CALENDAR_URI, null, null, null, null);
String[] s = c.getColumnNames();
if (c.moveToFirst())
{
while (c.moveToNext())
{
String _id = c.getString(c.getColumnIndex("_id"));
String CalId = c.getString(c.getColumnIndex("calendar_id"));
if ((_id==null) && (CalId == null))
{
return false;
}
else
{
if (_id.equals(eventId) && CalId.equals(cal_Id))
{
Uri uri = ContentUris.withAppendedId(CALENDAR_URI, Integer.parseInt(_id));
context.getContentResolver().update(uri, null, null, null);// need to give your data here
return true;
}
}
}
}
}
finally
{
return true;
}
}
However when I run it the getColumnNames doesn't get called and the code jumps straight to the line context.getContentResolver().update(uri, null, null, null); and then exits.
I put a couple of test events in my Calendar, why is the code not picking them up?
use this to add event to calender to particular date and time
Uri event1;
long epoch;
long epoch1;
Uri EVENTS_URI = Uri.parse(getCalendarUriBase(this) + "events");
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
try
{
epoch = new java.text.SimpleDateFormat ("yyyy-MM-dd hh:mm").parse(YourStartDate+" "+YourStratTime).getTime();
//epoch=epoch;
Log.e("epoch",String.valueOf(epoch));
epoch1 = new java.text.SimpleDateFormat ("yyyy-MM-dd hh:mm").parse(YourStartDate+" "+YourEndDate).getTime();
//epoch1=epoch1;
Log.e("epoch1",String.valueOf(epoch1));
} catch (ParseException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
values.put("calendar_id", 1);
values.put("title", "Appoitment");
values.put("allDay", 0);
values.put("dtstart",epoch); // event starts at 11 minutes from now
values.put("dtend", epoch1 ); // ends 60 minutes from now
values.put("description", "Your consulting date and time ");
values.put("visibility", 0);
values.put("hasAlarm", 1);
if(EVENTS_URI!=null)
{
event1 = cr.insert(EVENTS_URI, values);
}
// reminder insert
Uri REMINDERS_URI = Uri.parse(getCalendarUriBase(this) + "reminders");
values = new ContentValues();
values.put( "event_id", Long.parseLong(event1.getLastPathSegment()));
values.put( "method", 1 );
values.put( "minutes", 10 );
if(REMINDERS_URI!=null)
{
cr.insert( REMINDERS_URI, values );
}
getCalendarUroBase function:
private String getCalendarUriBase(Activity act) {
String calendarUriBase = null;
Uri calendars = Uri.parse("content://calendar/calendars");
Cursor managedCursor = null;
try {
managedCursor = act.managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
}
if (managedCursor != null) {
calendarUriBase = "content://calendar/";
} else {
calendars = Uri.parse("content://com.android.calendar/calendars");
try {
managedCursor = act.managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
}
if (managedCursor != null) {
calendarUriBase = "content://com.android.calendar/";
}
}
return calendarUriBase;
}
Note: As per Sample Date should be in yyyy-MM-dd, time should be in hh:mm formats
Related
I am saving an event in the device calendar with the below code
ContentResolver cr = getCurrentContext().getContentResolver();
ContentValues values = new ContentValues();
Calendar startDate = Calendar.getInstance();
startDate.setTimeInMillis(contentDatum.getGist().getScheduleStartDate());
Calendar endDate = Calendar.getInstance();
endDate.setTimeInMillis(contentDatum.getGist().getScheduleEndDate());
values.put(CalendarContract.Events.DTSTART, startDate.getTimeInMillis());
values.put(CalendarContract.Events.DTEND, endDate.getTimeInMillis());
values.put(CalendarContract.Events.TITLE, contentDatum.getGist().getTitle());
values.put(CalendarContract.Events.DESCRIPTION, contentDatum.getGist().getDescription());
values.put(CalendarContract.Events.CALENDAR_ID, getCalendarId());
values.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
long eventID = Long.parseLong(uri.getLastPathSegment());
Log.e("event", "" + eventID);
setCalendarEventId(eventID);
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setData(ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventID));
getCurrentActivity().startActivityForResult(intent, 0);
I am saving the eventID it returns when it is inserted.
To retrieve the data on the basis of event id, i am using the below code
for (int i = 0; i < calendarEventIds.length; i++) {
long eventID = Long.parseLong(calendarEventIds[i]);
Uri event = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventID);
Cursor cursor;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
cursor = getCurrentContext().getContentResolver().query(event, null, null, null);
} else {
cursor = getCurrentActivity().managedQuery(event, null, null, null, null);
}
if (cursor.getCount() == 1) {
if (cursor.moveToFirst()) {
if (cursor.getLong(cursor.getColumnIndex(CalendarContract.Events.DTSTART)) == contentDatum.getGist().getScheduleStartDate()
&& cursor.getLong(cursor.getColumnIndex(CalendarContract.Events.DTEND)) == contentDatum.getGist().getScheduleEndDate()
&& cursor.getString(cursor.getColumnIndex(CalendarContract.Events.TITLE)).equalsIgnoreCase(contentDatum.getGist().getTitle())
&& cursor.getString(cursor.getColumnIndex(CalendarContract.Events.DESCRIPTION)).equalsIgnoreCase(contentDatum.getGist().getDescription())) {
Toast.makeText(getCurrentContext(), "Event already exists in your calendar.", Toast.LENGTH_SHORT).show();
calendarEventExist = true;
}
}
}
}
However I do not the details of the event I added.
I was saving the calendar id's in comma separated string. The below code works perfectly fine for fetching the details of event
if (getCalendarEventId() != null) {
String[] calendarEventIds = getCalendarEventId().split(";");
for (int i = 0; i < calendarEventIds.length; i++) {
long eventID = Long.parseLong(calendarEventIds[i]);
Uri event = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventID);
Cursor cursor;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
cursor = getCurrentContext().getContentResolver().query(event, null, null, null);
} else {
cursor = getCurrentActivity().managedQuery(event, null, null, null, null);
}
if (cursor.moveToFirst()) {
do {
if ((cursor.getInt(cursor.getColumnIndex(CalendarContract.Events.DELETED)) == 1)) {
//The added event was deleted and is not visible in calendar but exists in calendar DB
calendarEventExist = false;
break;
}
if (cursor.getString(cursor.getColumnIndex(CalendarContract.Events.TITLE)).equalsIgnoreCase(contentDatum.getGist().getTitle())
&& cursor.getString(cursor.getColumnIndex(CalendarContract.Events.DESCRIPTION)).equalsIgnoreCase(contentDatum.getGist().getDescription())) {
Toast.makeText(getCurrentContext(), "Event already exists in your calendar.", Toast.LENGTH_SHORT).show();
calendarEventExist = true;
break;
}
} while (cursor.moveToNext());
}
}
} else {
calendarEventExist = false;
}
I am new to the android development. I am working on calender application where i need to add/delete and get all events in between the date range. I have add and delete the events successufully but problem is when i am getting the calender events in between the date range. I am getting the calender events but when i go to SPlanner i can see those events are not added in the calender as i have already deleted them. I do not know from where i am getting those events.Please suggest. Here is the code i have written to get the calender events:-
public void onGetEvent (final String fullCallbackName, String title,String startDate,String endDate) throws JSONException
{
try
{
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
final ArrayList<JSONObject> calEvents = new ArrayList();
if(calEvents.size() !=0)
{
calEvents.clear();
}
ContentResolver contentResolver = getContentResolver();
String selection = "((dtstart >= "+(dateFormat.parse(startDate).getTime())+") AND (dtend <= "+(dateFormat.parse(endDate).getTime())+"))";
Cursor cursor = contentResolver.query(Uri.parse(getCalendarUriBase() + "events"),
(new String[] { "_id", "title", "dtstart","dtend","eventLocation","description"}), selection, null, null);
Log.e("cursor.getCount before:","callbackFuncName:" + cursor.getCount());
while (cursor.moveToNext()) {
String _id = cursor.getString(0);
String displayName = cursor.getString(1);
Log.e("cursor.getCount before:","callbackFuncName:" + displayName);
String[] separated = displayName.split(":");
if(separated[0]!= null && title.equals(separated[0]))
{
JSONObject dictionary = new JSONObject();
String dstart = dateFormat.format(new Date(Long.parseLong(cursor.getString(2))));//cursor.getString(2);
String dEnd = dateFormat.format(new Date(Long.parseLong(cursor.getString(3))));//cursor.getString(3);
String eventlocation = cursor.getString(4);
String description = cursor.getString(5);
dictionary.put("identifier", _id);
dictionary.put("title", displayName);
dictionary.put("startDate", dstart);
dictionary.put("endDate", dEnd);
dictionary.put("venue", eventlocation);
dictionary.put("notes", description);
calEvents.add(dictionary);
}
}
if(fullCallbackName != null && !fullCallbackName.equals(""))
{
runOnUiThread(new Runnable() {
public void run()
{
webView.loadUrl("javascript:"+fullCallbackName+" ("+calEvents+")") ;
}
});
}
}
catch(Exception e)
{
Log.e("string", e.toString());
}
}
}
code for getting the calender DB is:-
private String getCalendarUriBase() {
String calendarUriBase = null;
Uri calendars = Uri.parse("content://calendar/calendars");
Cursor cursor = null;
try {
cursor = managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
// eat
}
if (cursor != null) {
calendarUriBase = "content://calendar/";
} else {
calendars = Uri.parse("content://com.android.calendar/calendars");
try {
cursor = managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
// eat
}
if (cursor != null) {
calendarUriBase = "content://com.android.calendar/";
}
}
Log.d("Sandeep",
calendarUriBase);
// managedCursor.close();
return calendarUriBase;
}
With your query you will see deleted events because they are still in the database (for being able to sync the deletion whenever the next sync is due). That's what the DELETED column is for.
To find all events between a start and end date use the Instances class of the CalendarContract API as in the code below. This code returns only visible events!
I've written a blog post about the CalendarContract content provider detailing this and other stuff.
long begin = // starting time in milliseconds; for you probably cursor.getLong(2)
long end = // ending time in milliseconds; cursor.getLong(3)
String[] proj =
new String[]{
Instances._ID,
Instances.TITLE,
Instances.BEGIN,
Instances.END,
Instances.EVENT_LOCATION,
Instances.DESCRIPTION,
Instances.EVENT_ID};
Cursor cursor =
Instances.query(getContentResolver(), proj, begin, end);
if (cursor.getCount() > 0) {
// do your JSON thing
}
I facing a events details saving in android calendar from the long time. I am able to save the details in devices below android version 2.2.3 but for above it doesn't save to calendar. Here is my code:
Calendar cal = Calendar.getInstance();
Uri events = null;
if(getCalendarUriBase(this)!=null)
{
Uri EVENTS_URI = Uri.parse(getCalendarUriBase(this) + "events");
ContentResolver cr = getContentResolver();
// event insert
long eventdate1=Date.parse(“23/07/2012”);
long eventdate2=Date.parse((“23/07/2012”);
ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title","Event 1");
values.put("allDay", 0);
values.put("dtstart", eventdate1); // event starts at 11 minutes from now
values.put("dtend", eventdate2); // ends 60 minutes from now
values.put("description", "Description 1");
values.put("eventLocation", "xyz");
values.put("visibility", 0);
values.put("hasAlarm", 1);
try{
try{
events = cr.insert(EVENTS_URI, values);
}catch (Exception e) {
// TODO: handle exception
return false;
}
// reminder insert
Uri REMINDERS_URI = Uri.parse(getCalendarUriBase(this) + "reminders");
values = new ContentValues();
values.put( "event_id", Long.parseLong(events.getLastPathSegment()));
values.put( "method", 1 );
values.put( "minutes", 10 );
cr.insert( REMINDERS_URI, values );
private String getCalendarUriBase(Activity act) {
String calendarUriBase = null;
Uri calendars = Uri.parse("content://calendar/calendars");
Cursor managedCursor = null;
try {
managedCursor = act.managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
}
if (managedCursor != null) {
calendarUriBase = "content://calendar/";
} else {
calendars = Uri.parse("content://com.android.calendar/calendars");
try {
managedCursor = act.managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
}
if (managedCursor != null) {
calendarUriBase = "content://com.android.calendar/";
}
}
return calendarUriBase;
}
******
Where I am missing something. Please help me on it.
I had a similar problem. I think the problem is in
values.put("visibility", 0);
I think that there is no column in database with that name. It's the same with column named transparency. I found it in some tutorials on the net
I have problem with adding events to Android Calendar.
My minimum SDK version is 7. I use Intent to add event, but problems is with various API.
I use this:
String eventUriString;
if (Build.VERSION.SDK_INT > 7)
eventUriString = "content://com.android.calendar/events";
else eventUriString = "content://calendar/events";
ContentValues eventValues = new ContentValues();
eventValues.put("calendar_id", 1);
eventValues.put("title", "title");
eventValues.put("description", desc);
eventValues.put("eventLocation", "");
long endDate = startDate + 1000 * 60 * 60;
eventValues.put("dtstart", MyClass.getDate());
eventValues.put("dtend", endDate);
eventValues.put("eventStatus", 0);
eventValues.put("visibility", 2);
eventValues.put("transparency", 0);
eventValues.put("hasAlarm", 0);
Uri eventUri = context.getContentResolver().insert(Uri.parse(eventUriString), eventValues);
long eventID = Long.parseLong(eventUri.getLastPathSegment());
to Edit some events I use:
String calendarUriBase = null;
long id = MyEvents.getID(p); //something ID from my another class
Uri calendars = Uri.parse("content://calendar/calendars");
Cursor managedCursor = null;
try {
managedCursor = managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
// eat
}
if (managedCursor != null) {
calendarUriBase = "content://calendar/";
} else {
calendars = Uri.parse("content://com.android.calendar/calendars");
try {
managedCursor = managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
// eat
}
if (managedCursor != null) {
calendarUriBase = "content://com.android.calendar/";
}
}
ContentValues event = new ContentValues();
event.put("title", "new Title");
Uri eventsUri = Uri.parse(calendarUriBase+"events");
Uri eventUri = ContentUris.withAppendedId(eventsUri, id);
getContentResolver().update(eventUri, event, null, null);
and it work on my phone (SE X8 with Android 2.3.7) but doesn't work on SDK 14.
Is anywhere universal code, which I can use to add events to Calendar Android works on every various SDK? I have no idea how it make. I must use API 7 because my manager want. Have you any ideas how do that?
In ICS a new Calendar API is introduced so your code will not work in ICS.
New Public APIs in ICS
In order to support adding events to all calendars you can change your code like this -
if (Build.VERSION.SDK_INT >= 14) {
saveCalendarEventICS();
}
else {
int cal_id = getCalendar_ID();
if(cal_id != 0){
saveCalendarEvent(cal_id);
}
}
private int getCalendar_ID() {
// TODO Auto-generated method stub
int calendar_id = 0;
String[] projection = new String[] { "_id", "name" };
String selection = "selected=1";
String path = "calendars";
Cursor calendarCursor = getCalendarCursor(projection, selection, path);
if (calendarCursor != null && calendarCursor.moveToFirst()) {
int nameColumn = calendarCursor.getColumnIndex("name");
int idColumn = calendarCursor.getColumnIndex("_id");
do {
String calName = calendarCursor.getString(nameColumn);
String calId = calendarCursor.getString(idColumn);
if (calName != null /*&& calName.contains("Test")*/) {
calendar_id = Integer.parseInt(calId);
}
} while (calendarCursor.moveToNext());
}
return calendar_id;
}
private void saveCalendarEventICS() {
Intent intent = new Intent(Intent.ACTION_INSERT)
.setType("vnd.android.cursor.item/event")
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, frsttime)
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, sncdtime)
.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY , false) // just included for completeness
.putExtra(Events.TITLE, vl_hldr[0])
.putExtra(Events.DESCRIPTION, vl_hldr[2])
.putExtra(Events.EVENT_LOCATION, vl_hldr[1])
.putExtra(Events.RRULE, "FREQ=DAILY;COUNT=10")
.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY)
.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE)
.putExtra(Events.ALLOWED_REMINDERS, "METHOD_DEFAULT")
.putExtra(Intent.EXTRA_EMAIL, "");
startActivity(intent);
}
private void saveCalendarEvent(int calid) {
// TODO Auto-generated method stub
//Create the event here -----------
Uri newEvent;
if (Build.VERSION.SDK_INT >= 8) {
//newEvent = Uri.parse("content://com.android.calendar/events");
newEvent = ctx.getContentResolver().insert(Uri.parse("content://com.android.calendar/events"), event);
if (newEvent != null) {
long id = Long.parseLong( newEvent.getLastPathSegment() );
ContentValues values = new ContentValues();
values.put( "event_id", id );
values.put( "method", 1 );
values.put( "minutes", 15 ); // 15 minuti
getContentResolver().insert( Uri.parse( "content://com.android.calendar/reminders" ), values );
}
}
else {
newEvent = ctx.getContentResolver().insert(Uri.parse("content://calendar/events"), event);
if (newEvent != null) {
long id = Long.parseLong( newEvent.getLastPathSegment() );
ContentValues values = new ContentValues();
values.put( "event_id", id );
values.put( "method", 1 );
values.put( "minutes", 15 ); // 15 minuti
getContentResolver().insert( Uri.parse( "content://calendar/reminders" ), values );
}
}
}catch(Exception ee){}
}
I am trying to add an event to the android calendar, and I specify that the event will be added to the gmail calendar in order to sync with the Google calendar automatically.
The problem is events added programmatically don't sync with Google calendar, but if I add it manual on the phone it does sync with Google calendar. I don't know why.
This is the code that I use to add the event:
ArrayList<MyCalendar> calendars = new ArrayList<MyCalendar>();
String[] projection = new String[] { "_id", "name" };
Uri calUri = getCalendarURI(false);
Cursor managedCursor = managedQuery(calUri, projection, "selected=1",
null, null);
String calName = null;
String calId = null;
if (managedCursor.moveToFirst()) {
int nameColumn = managedCursor.getColumnIndex("name");
int idColumn = managedCursor.getColumnIndex("_id");
do {
calName = managedCursor.getString(nameColumn);
calId = managedCursor.getString(idColumn);
calendars.add(new MyCalendar(Integer.parseInt(calId), calName));
} while (managedCursor.moveToNext());
}
Toast.makeText(getBaseContext(), calName + " " + calId,
Toast.LENGTH_LONG).show();
Calendar cal = Calendar.getInstance();
ContentValues event = new ContentValues();
event.put("calendar_id", 2);
event.put("title", "Test Event2");
event.put("description", "Hiii Buddy");
long startTime = cal.getTimeInMillis();
long endTime = cal.getTimeInMillis() + 60 * 60 * 1000;
event.put("dtstart", startTime);
event.put("dtend", endTime);
event.put("allDay", 0);
event.put("eventStatus", 1);// tentative 0, confirmed 1 canceled 2
event.put("visibility", 3);// default 0 confidential 1 private 2
// public 3
event.put("transparency", 0);// opaque 0 transparent 1
event.put("hasAlarm", 1); // 0 false, 1 true
Uri eventsUri = getCalendarURI(true);
Uri url = getContentResolver().insert(eventsUri, event);
So the event successfully added to calendar but it doesn't show up in the Google calendar at the web (don't sync) but if I add the event manually it does sync !!!
You can sync your event after adding it by this function,It's worked for me(in API 8 and later):
public static void syncCalendar(Context context, String calendarId) {
ContentResolver cr = context.getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
values.put(CalendarContract.Calendars.VISIBLE, 1);
cr.update(
ContentUris.withAppendedId(getCalendarUri(),
Long.parseLong(calendarId)), values, null, null);
}
Try this code to insert an event into the android calendar as well as google calendar:
ContentValues values = new ContentValues();
cal_id = String.valueOf(p1);
values.put("calendar_id", p1);
values.put("title", title1);
values.put("allDay", 0);
values.put("dtstart", settime);
values.put("dtend", cal.getTimeInMillis()+60*60*1000);
values.put("description", desc1);
values.put("visibility", 0);
values.put("transparency", 0);
values.put("hasAttendeeData", 1);
values.put("hasAlarm", 0);
event = cr.insert(EVENTS_URI, values);
event1=event;
dat1 = event.toString();
long id=-1;
if (event != null)
{
id = Long.parseLong(event.getLastPathSegment());
ContentValues values1 = new ContentValues();
values1.put("event_id", id);
values1.put("method", 1); //METHOD_ALERT
Uri reminder = Uri.parse(getCalendarUriBase(this) + "reminders");
this.getContentResolver().insert(reminder, values1);
if(s.length() > 0 || partmail.length() > 0)
{
//REQUIRES FOLLOWING CODE
This code is used to add the event sync'ed to the google calendar
ContentValues attendees = new ContentValues();
attendees.put("event_id", id);
attendees.put("attendeeEmail", partmail1);
attendees.put("attendeeRelationship", 2);//RELATIONSHIP_ATTENDEE
attendees.put("attendeeStatus", 3); //ATTENDEE_STATUS_INVITED
attendees.put("attendeeType", 1); //TYPE_REQUIRED
id1=(int)id;
alarmid = (int) id;
Uri attendeesUri = null;
if (Integer.parseInt(Build.VERSION.SDK) >= 8 )
{
attendeesUri = Uri.parse("content://com.android.calendar/attendees");
}
else if(Integer.parseInt(Build.VERSION.SDK) < 8)
{
attendeesUri = Uri.parse("content://calendar/attendees");
}
this.getContentResolver().insert(attendeesUri, attendees);
Toast.makeText(this, "Task Scheduled Successfully", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, "Could not create Task!", Toast.LENGTH_SHORT);
}
// reminder insert
Uri REMINDERS_URI = Uri.parse(getCalendarUriBase(this) + "reminders");
values = new ContentValues();
values.put( "event_id", id);
values.put( "method", 1 );
values.put( "minutes", 0 );
cr.insert( REMINDERS_URI, values );
Get Calendar's Uri since it differs for API levels such as till 8, greater than 8 and greater than 11.
private String getCalendarUriBase(Context con) {
String calendarUriBase = null;
Uri calendars = Uri.parse("content://calendar/calendars");
Cursor managedCursor = null;
try {
managedCursor = managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
// eat
}
if (managedCursor != null) {
calendarUriBase = "content://calendar/";
} else {
calendars = Uri.parse("content://com.android.calendar/calendars");
try {
managedCursor = managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
// statement to print the stacktrace
}
if (managedCursor != null) {
calendarUriBase = "content://com.android.calendar/";
}
}
return calendarUriBase;
}
Use the google calender api provided here
The above reference is somewhat general as Android doesn’t provide an official API. So, another solution more android specific is An Android Tutorial–Programming with Calendar
which contains a working example too. Also, be careful at Permission Declaration like READ_CALENDAR , WRITE_CALENDAR