Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old February 1st, 2011, 08:52 AM   #1 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Jan 2011
Posts: 21
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default Unable to create calendar event

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

pedjasmek is offline  
Reply With Quote
sponsored links
Old February 1st, 2011, 09:34 AM   #2 (permalink)
ROM Developer
 
cr5315's Avatar
 
Join Date: Jul 2010
Location: Narnia
Posts: 435
 
Device(s): Current: HTC Evo 4G, Asus Nexus 7 Retired: LG Ally
Carrier: Not Provided

Thanks: 103
Thanked 161 Times in 105 Posts
Default

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
__________________

(That's a link. Just saying.)
cr5315 is offline  
Reply With Quote
Old February 1st, 2011, 09:46 AM   #3 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Jan 2011
Posts: 21
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default

Still the same
pedjasmek is offline  
Reply With Quote
Old February 1st, 2011, 10:28 AM   #4 (permalink)
ROM Developer
 
cr5315's Avatar
 
Join Date: Jul 2010
Location: Narnia
Posts: 435
 
Device(s): Current: HTC Evo 4G, Asus Nexus 7 Retired: LG Ally
Carrier: Not Provided

Thanks: 103
Thanked 161 Times in 105 Posts
Default

Try

Code:
content://calendar/events
or
Code:
content://calendar
I got that from
Jim Blackler Accessing the internal calendar database inside Google Android applications
cr5315 is offline  
Reply With Quote
Old February 2nd, 2011, 04:18 AM   #5 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Jan 2011
Posts: 21
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default

Funny thing,I've just noticed that I don't have a calendar application in my emulator.Can anyone tell how add one?
pedjasmek is offline  
Reply With Quote
Old February 2nd, 2011, 10:23 AM   #6 (permalink)
ROM Developer
 
cr5315's Avatar
 
Join Date: Jul 2010
Location: Narnia
Posts: 435
 
Device(s): Current: HTC Evo 4G, Asus Nexus 7 Retired: LG Ally
Carrier: Not Provided

Thanks: 103
Thanked 161 Times in 105 Posts
Default

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.
cr5315 is offline  
Reply With Quote
Old February 2nd, 2011, 12:49 PM   #7 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Jan 2011
Posts: 21
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default

I tried to use calendar in my gmail profile because Google has the api for it.I managed to create an event there.
pedjasmek is offline  
Reply With Quote
Old March 1st, 2011, 12:44 AM   #8 (permalink)
New Member
 
Join Date: Mar 2011
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Events Calendar

Quote:
Originally Posted by pedjasmek View Post
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
antonykk is offline  
Reply With Quote
Old March 1st, 2011, 12:45 AM   #9 (permalink)
New Member
 
Join Date: Mar 2011
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can try with this example Android Codes: calendar
antonykk is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:38 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.