Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I post you this code that is used in one of my app in the market. It adds automatically event to the user calendar. It doesn't use Intent that requires an user action.</p> <pre><code>public void addEvent(CalendarEvent evt) { //Log.d(Params.LOG_APP, "Insert event ["+evt+"]"); try { Uri evtUri = ctx.getContentResolver().insert(getCalendarUri("events"), CalendarEvent.toContentValues(evt)); Log.d(Params.LOG_APP, "" + evtUri); } catch(Throwable t) { //Log.e(Params.LOG_APP, "", t); } } public void setContext(Context context) { this.ctx = context; this.baseUri = getCalendarUriBase(); } private Uri getCalendarUri(String path) { return Uri.parse(baseUri + "/" + path); } private String getCalendarUriBase() { String calendarUriBase = null; Uri calendars = Uri.parse("content://calendar/calendars"); Cursor managedCursor = null; try { managedCursor = ctx.getContentResolver().query(calendars, null, null, null, null); } catch (Exception e) { // e.printStackTrace(); } if (managedCursor != null) { calendarUriBase = "content://calendar/"; } else { calendars = Uri.parse("content://com.android.calendar/calendars"); try { managedCursor = ctx.getContentResolver().query(calendars, null, null, null, null); } catch (Exception e) { // e.printStackTrace(); } if (managedCursor != null) { calendarUriBase = "content://com.android.calendar/"; } } Log.d(Params.LOG_APP, "URI ["+calendarUriBase+"]"); return calendarUriBase; } </code></pre> <p>And for ICS and later</p> <pre><code>public void addEvent(CalendarEvent evt) { ContentResolver cr = context.getContentResolver(); Uri uri = cr.insert(Events.CONTENT_URI, CalendarEvent.toICSContentValues(evt)); System.out.println("Event URI ["+uri+"]"); } </code></pre> <p>CalendarEvent is like</p> <pre><code>public static ContentValues toContentValues(CalendarEvent evt) { ContentValues cv = new ContentValues(); cv.put("calendar_id", evt.getIdCalendar()); cv.put("title", evt.getTitle()); cv.put("description", evt.getDescr()); cv.put("eventLocation", evt.getLocation()); cv.put("dtstart", evt.getStartTime()); cv.put("dtend", evt.getEndTime()); cv.put("eventStatus", 1); cv.put("visibility", 0); cv.put("transparency", 0); return cv; } public static ContentValues toICSContentValues(CalendarEvent evt) { ContentValues cv = new ContentValues(); cv.put(Events.CALENDAR_ID, evt.getIdCalendar()); cv.put(Events.TITLE, evt.getTitle()); cv.put(Events.DESCRIPTION, evt.getDescr()); cv.put(Events.EVENT_LOCATION, evt.getLocation()); cv.put(Events.DTSTART, evt.getStartTime()); cv.put(Events.DTEND, evt.getEndTime()); Calendar cal = Calendar.getInstance(); TimeZone tz = cal.getTimeZone(); cv.put(Events.EVENT_TIMEZONE, tz.getDisplayName()); /* cv.put(Events.STATUS, 1); cv.put(Events.VISIBLE, 0); cv.put("transparency", 0); return cv; */ return cv; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload