Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8462175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:05:44+00:00 2026-06-10T14:05:44+00:00

I have problem with adding events to Android Calendar. My minimum SDK version is

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:05:45+00:00Added an answer on June 10, 2026 at 2:05 pm

    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){}
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a problem with adding Expanded event to my Expanders. I have expanders
I have one problem while adding multiple events more than 70 events repeatedly again
What I want: I want to add calendar events in Android 2.2. What I
I am having a problem with adding events back to the calendar after they
I have problem adding arraylist to list view, will explain about my problem here..
I have a problem adding ADO.Net Entity Data Model to my existing project, or
I have a problem adding entities to a collection. public void SaveNotificationUsergroups(int bookingobjectID, int[]
I have a problem with adding OPTIONS to SELECT tag dynamically. Here is my
I have a problem with adding filter for attribute, which exist not in all
I have a little problem with adding actions on UITabBarItems. I am not using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.