开发者

Android Calendar

开发者 https://www.devze.com 2023-03-12 20:21 出处:网络
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.

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);
    even开发者_开发技巧t.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.


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 .


  1. You could do this in a couple different ways, but the best way I would recommend is using a SQLite Database for storing your calendar events.
  2. You will use standard SQL insert statements to add your events to your calendar database.
  3. You will use standard select (query) statements to retrieve your events.


To update Google Calendar, use the Google Calendar GData API.

0

精彩评论

暂无评论...
验证码 换一张
取 消