Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Calendar

I am trying to put items into a calendar and can't really find out how to code it. This is what I have so far but it inserts it into the main calendar.

    String calName; 
    String calId = null;
    String[] projection = new String[] { "_id", "name" };

    Uri calendars = Uri.parse("content://calendar/calendars");
    Cursor managedCursor = managedQuery(calendars, projection, null, null, null);
    ContentValues event = new ContentValues();

    event.put("calendar_id", calId);
    event.put("title", strTitle);
    event.put("description", strDescription);
    event.put("eventLocation", strLocation);
    event.put("dtstart", StartTime);
    event.put("dtend", EndTime);

    Uri eventsUri = Uri.parse("content://calendar/events");
    Uri calUri = getContentResolver().insert(eventsUri, event);

So my questions are:

  1. How do I create my own calendar to put events into

  2. How do I insert my events into that calendar (using the code above or a new code)

  3. How do I check to see if event already exists

~~~UPDATE:~~~

What I'm trying to do is my users will enter in an title and a date and my app will take that title and date, put them into a database (so far all that I have done) and now I want to take the title and date and put them into a special calendar devoted for just my apps events. First thing I need to do is have the app create a new calendar. Than insert events into that calendar which the code below helps me do kind of. Still playing with it. Than I want to rerun my app and check to see if the event exists. Thats all.

like image 509
TRIALandERROR Avatar asked Jun 11 '11 20:06

TRIALandERROR


1 Answers

First of all the content resolver changes since 2.2 I think from content://calendar/calendars to content://com.android.calendar/calendars.

To insert Event , retrieve Event check this code

https://github.com/Rabgs/AndroidLib_Google-Calendar/blob/master/src/net/mobiwide/agenda/google/GoogleAgenda.java

You will find everything you need and how to handle the content resolver change across platforms .

like image 112
Rick Avatar answered Sep 27 '22 18:09

Rick