1. Check out our companion app, Forums for Android! Download from Google Play

Unable to create calendar event

Discussion in 'Application Development' started by pedjasmek, Feb 1, 2011.

  1. pedjasmek

    pedjasmek Member
    Thread Starter
    15

    Jan 14, 2011
    21
    0
    15
    I am trying to create a calendar event using this code:

    Code (Text):
    1.  
    2. ContentValues event = new ContentValues();
    3.  
    4.             event.put("calendar_id", calId);
    5.             event.put("title", subject);
    6.             event.put("description", "");
    7.             event.put("eventLocation", "");
    8.  
    9.             long startTime = System.currentTimeMillis() + 1000 * 60 * 60;
    10.             long endTime = System.currentTimeMillis() + 1000 * 60 * 60 * 2;
    11.  
    12.             event.put("dtstart", startTime);
    13.             event.put("dtend", endTime);
    14.  
    15.             event.put("allDay", 0); // 0 for false, 1 for true
    16.             event.put("eventStatus", 1);
    17.             event.put("visibility", 0);
    18.             event.put("transparency", 0);
    19.             event.put("hasAlarm", 0); // 0 for false, 1 for true
    20.  
    21.             Uri eventsUri = Uri.parse("content://com.android.calendar/events");
    22.  
    23.             Uri insertedUri = getContentResolver().insert(eventsUri, event);
    24.  
    but I am getting this exception : "java.lang.IllegalArgumentException: Unknown URL content://com.android.calendar/events".
    Can anyone tell what is the proper uri?Thanks
     

    Advertisement

  2. cr5315

    cr5315 Well-Known Member
    68

    Jul 23, 2010
    435
    158
    68
    Narnia
    Make sure you've added this to you Android Manifest

    Code (Text):
    1. <uses-permission
    2.   android:name="android.permission.READ_CALENDAR">
    3.   </uses-permission>
    4. <uses-permission
    5.    android:name="android.permission.WRITE_CALENDAR">
    6.    </uses-permission>
    Also, try calendar.events instead of calendar/events
     
  3. pedjasmek

    pedjasmek Member
    Thread Starter
    15

    Jan 14, 2011
    21
    0
    15
    Still the same :(
     
  4. cr5315

    cr5315 Well-Known Member
    68

    Jul 23, 2010
    435
    158
    68
    Narnia
  5. pedjasmek

    pedjasmek Member
    Thread Starter
    15

    Jan 14, 2011
    21
    0
    15
    Funny thing,I've just noticed that I don't have a calendar application in my emulator.Can anyone tell how add one?
     
  6. cr5315

    cr5315 Well-Known Member
    68

    Jul 23, 2010
    435
    158
    68
    Narnia
    You would need the .apk for the Android Calendar and then I think you would have to use the adb to push it to the emulator, but I'm not sure if that's right.
     
  7. pedjasmek

    pedjasmek Member
    Thread Starter
    15

    Jan 14, 2011
    21
    0
    15
    I tried to use calendar in my gmail profile because Google has the api for it.I managed to create an event there.
     
  8. antonykk

    antonykk New Member
    5

    Mar 1, 2011
    3
    0
    5

    Actually you can get the fully working code from this site Android Codes: calendar http://android-codes-examples.blogspot.com/search/label/calendar
     
  9. antonykk

    antonykk New Member
    5

    Mar 1, 2011
    3
    0
    5

Share This Page

Loading...