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 6936697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:16:02+00:00 2026-05-27T12:16:02+00:00

I need to be able to create an event in the Google Calendar from

  • 0

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?

  • 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-05-27T12:16:03+00:00Added an answer on May 27, 2026 at 12:16 pm

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually I need to create an event in Google Calendar using my app. Every
I need to create a recurring event in SharePoint calendar. I am able to
I need to be able to create tweets from shared items on google reader
I need to be able to create basic MS Project items (tasks, projects, resources,
I need to be able to create a UserSession without having the decrypted password.
I need to be able to create a seperate function which creates a total
In order to create the proper queries I need to be able to run
I am attempting to create a table in rails.. I need to be able
I need to create a configuration section, that is able to store key-value pairs
I've created a global handler for ajaxSuccess , but I need to be able

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.