• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Unable to create calendar event

pedjasmek

Newbie
I am trying to create a calendar event using this code:

Code:
ContentValues event = new ContentValues();

	        event.put("calendar_id", calId);
	        event.put("title", subject);
	        event.put("description", "");
	        event.put("eventLocation", "");

	        long startTime = System.currentTimeMillis() + 1000 * 60 * 60;
	        long endTime = System.currentTimeMillis() + 1000 * 60 * 60 * 2;

	        event.put("dtstart", startTime);
	        event.put("dtend", endTime);

	        event.put("allDay", 0); // 0 for false, 1 for true
	        event.put("eventStatus", 1);
	        event.put("visibility", 0);
	        event.put("transparency", 0);
	        event.put("hasAlarm", 0); // 0 for false, 1 for true

	        Uri eventsUri = Uri.parse("content://com.android.calendar/events"); 

	        Uri insertedUri = getContentResolver().insert(eventsUri, event);

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
 
Make sure you've added this to you Android Manifest

Code:
<uses-permission
  android:name="android.permission.READ_CALENDAR">
  </uses-permission>
<uses-permission
   android:name="android.permission.WRITE_CALENDAR">
   </uses-permission>

Also, try calendar.events instead of calendar/events
 
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.
 
I am trying to create a calendar event using this code:

Code:
ContentValues event = new ContentValues();

            event.put("calendar_id", calId);
            event.put("title", subject);
            event.put("description", "");
            event.put("eventLocation", "");

            long startTime = System.currentTimeMillis() + 1000 * 60 * 60;
            long endTime = System.currentTimeMillis() + 1000 * 60 * 60 * 2;

            event.put("dtstart", startTime);
            event.put("dtend", endTime);

            event.put("allDay", 0); // 0 for false, 1 for true
            event.put("eventStatus", 1);
            event.put("visibility", 0);
            event.put("transparency", 0);
            event.put("hasAlarm", 0); // 0 for false, 1 for true

            Uri eventsUri = Uri.parse("content://com.android.calendar/events"); 

            Uri insertedUri = getContentResolver().insert(eventsUri, event);
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


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