I have search all over, and I have found bits and pieces on adding events, for .net or php, but not java.
So how do you add events to a google calendar that was created by your program.
Heres what I have
I have is
CalendarEntry calendar, returned from when I created the calendar.
Entry entry, which is a valid event to be inserted in the calendar I created.
CalendarService service, which is a valid calendar service.
So based on the calendar variable, I want to generate a url to insert the event at, by calling
service.insert(url, entry);
I happened to find an answer from here http://www.danwalmsley.com/2008/09/23/free-sms-service-notifications-using-google-calendar/
String postUrlString = calendarEntry.getLink("alternate", "application/atom+xml").getHref();
Seems to work!
From the doc:
URL postURL = new URL("http://www.google.com/calendar/feeds/root#gmail.com/private/full");
CalendarEventEntry myEvent = new CalendarEventEntry();
//Set the title and description
myEvent.setTitle(new PlainTextConstruct("Pi Day Party"));
myEvent.setContent(new PlainTextConstruct("I am throwing a Pi Day Party!"));
//Create DateTime events and create a When object to hold them, then add
//the When event to the event
DateTime startTime = DateTime.parseDateTime("2007-03-14T15:00:00-08:00");
DateTime endTime = DateTime.parseDateTime("2007-03-14T17:00:00-08:00");
When eventTimes = new When();
eventTimes.setStartTime(startTime);
eventTimes.setEndTime(endTime);
myEvent.addTime(eventTimes);
// POST the request and receive the response:
CalendarEventEntry insertedEntry = myService.insert(postURL, myEvent);
And if you already have a CalendarEntry (not tested):
/* CalendarEntry calendar = ...; CalendarEventEntry myEvent = ... */
Service myService = calendar.getService();
myService.insert(new URL(calendar.getEditLink().getHref()), yourEvent)
You can use the Google's Data API for creating events. You can download the java library from here. The Developer's guide can help you get started with using the library.
Here the documentation on creating events: http://code.google.com/apis/calendar/data/2.0/developers_guide_java.html#CreatingEvents
Related
I am developing an application which reads all the events from the calendar.ics file and then display all the events. My code works fine with individual events and i am able to extract all the events from the file because it contains all the events.
But when i create recurring events then i can't get all the events except for the first one, because calendar.ics file contains "RRULE" instead of all the events.
I have tried "rfc2445.jar" but it didn't work or maybe i don't know exactly how to use it...
Is there any library/code/method/function anything which could help me to parse and display all the events?
CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = null;
calendar = builder.build(file);
Log.d("RRULE 1: ", component.getProperty("RRULE").getName());
Log.d("RRULE 2: ", component.getProperty("RRULE").getValue());
Log.d("RRULE 3: DTSTART: ",component.getProperty("DTSTART").getValue());
Log.d("RRULE 4: DTEND: ", component.getProperty("DTEND").getValue());
.......
above is the snippet of my code and i got the following results
D/RRULE 1:: RRULE
D/RRULE 2:: FREQ=DAILY;COUNT=184
D/RRULE 3: DTSTART:: 20160701T170000
D/RRULE 4: DTEND:: 20160701T200000
I don't know how to parse all the events from FREQ ?
You can use our library lib-recur.
The (very) basic usage (not accounting for time zones) would be as follows:
RecurrenceRule rule = new RecurrenceRule(component.getProperty("RRULE").getValue());
DateTime start = DateTime.parse(component.getProperty("DTSTART").getValue());
int maxInstances = 100; // limit instances for rules that recur forever
RecurrenceRuleIterator it = rule.iterator(start);
while (it.hasNext() && (!rule.isInfinite() || maxInstances-- > 0))
{
DateTime nextInstance = it.nextDateTime();
// do something with nextInstance
}
The library also supports multiple RRULEs, EXRULEs, EXDATEs, RDATEs and time zones.
Ok, so after trying really hard for some days i am still not able to make this work.
This is the problem: I have a JSP which hosts a Google chart that is going to be constructed from data that is going to be sent through a Servlet. I'm using the Google Visualization Java libraries to implement this servlet.
Then i have this helper function that, taking some data stored in a list of objects, constructs a datatable. Following is the class that implements said function:
public class DataTableGenerator {
public static DataTable generateDatatable(List<AccesoUrl> accesos) {
DataTable data = new DataTable();
ArrayList<ColumnDescription> cd = new ArrayList<>();
cd.add(new ColumnDescription("fecha", ValueType.DATE, "Fecha"));
cd.add(new ColumnDescription("navegador", ValueType.TEXT, "Navegador"));
cd.add(new ColumnDescription("ip", ValueType.TEXT, "IP"));
cd.add(new ColumnDescription("os", ValueType.TEXT, "Sistema Operativo"));
data.addColumns(cd);
try {
for(AccesoUrl acceso : accesos) {
GregorianCalendar calendario = new GregorianCalendar();
calendario.setTimeZone(TimeZone.getTimeZone("GMT"));
data.addRowFromValues(calendario, acceso.getNavegador(), acceso.getIp(), acceso.getSistemaoperativo());
}
} catch (TypeMismatchException e) {
System.out.println(e);
}
return data;
}
}
Now, this piece of code should work, but instead i am getting this exception on my web server:
com.google.visualization.datasource.base.TypeMismatchException: Value type mismatch.
at com.google.visualization.datasource.datatable.value.ValueType.createValue(Unknown Source)
at com.google.visualization.datasource.datatable.DataTable.addRowFromValues(Unknown Source)
I'm at wit's end now. I have tried every variation i could find on Google so that my JSP displays this data on a Google Table type of chart. I have tried sending a date as a string, a date as a string formatted as a javascript date (i.e "Date(2015,4,4)" or "new Date(2015,4,4)"). I have tried using the DateValue object that comes with the java visualization library to construct the date as well (i.e new DateValue(2015,4,4)). I have also tried passing a Java Date as well. Nothing works, everything throws a TypeMismatchException.
I am sure it's the date that's giving me trouble because as soon as i remove the date column from the datatable everything runs fine with no exception and i can get my data displayed on the Google chart table.
So can anybody please tell me what exactly do i have to do in my Java code to be able to construct a datatable with a date cell?
Even I faced same issue. But it seems addRowFromValues() doesn't support DateValue(). I siwtched to addRow(TableRow). Didnt see any error's.
You can use something like below,
Sample Code:
DataTable data = new DataTable();
ArrayList<ColumnDescription> cd = new ArrayList<ColumnDescription>();
cd.add(new ColumnDescription("date", ValueType.DATE, "Executed Date"));
cd.add(new ColumnDescription("value", ValueType.NUMBER, "Duration "));
data.addColumns(cd);
TableRow tr = new TableRow();
tr.addCell(new DateValue(2015,7,7));
data.addRow(tr);
I have an App which shows special Days. I want to integrate them into the calendar.
The events are static, they don't change, so I don't have to update the calendar very often.
I first thought of creating a local calendar and add the events, but new android versions (since 2.3?) seem not to support that; to implement I would have to create a Calendar Provider.
I saw this project on github: https://github.com/dschuermann/birthday-adapter. It is very complicated; its main use is adding the birthdays of the contacts to a new calendar.
There is lots of code, much of which I don't think I need. Do I really need to register to android's account manager to integrate a Calendar Provider? I just need a new Calendar with my event...
Would it be easier to take the user's default Calendar and add all the Events there? I could add some identifiers to the description, to be able to remove the events if the user doesn't want them.
Any tips, tutorials, or further readings are appreciated.
Metin Kale
You can create events in your device calendar via Intent. I think it could be useful for you.
public long addEventToCalender(ContentResolver cr, String title, String addInfo, String place, int status,
long startDate, boolean isRemind,long endDate) {
String eventUriStr = "content://com.android.calendar/events";
ContentValues event = new ContentValues();
// id, We need to choose from our mobile for primary its 1
event.put("calendar_id", 1);
event.put("title", title);
event.put("description", addInfo);
event.put("eventLocation", place);
event.put("eventTimezone", "UTC/GMT +2:00");
// For next 1hr
event.put("dtstart", startDate);
event.put("dtend", endDate);
//If it is bithday alarm or such kind (which should remind me for whole day) 0 for false, 1 for true
// values.put("allDay", 1);
// event.put("eventStatus", status);
event.put("hasAlarm", 1);
Uri eventUri = cr.insert(Uri.parse(eventUriStr), event);
long eventID = Long.parseLong(eventUri.getLastPathSegment());
if (isRemind) {
String reminderUriString = "content://com.android.calendar/reminders";
ContentValues reminderValues = new ContentValues();
reminderValues.put("event_id", eventID);
// Default value of the system. Minutes is a integer
reminderValues.put("minutes", 5);
// Alert Methods: Default(0), Alert(1), Email(2), SMS(3)
reminderValues.put("method", 1);
cr.insert(Uri.parse(reminderUriString), reminderValues); //Uri reminderUri =
}
return eventID;
}
For more information visit http://developer.android.com/reference/java/util/Calendar.html
In this reply you how to get contacts and birthdays.
Android Applicaiton - How to get birthday of a contact
and this library will offer you a powerful and flexible schedule so you can use
Caldroid Library
How to pass the mail id of the calendar that to be synchronized into the create event through email?
I have a spinner that shows the list of accounts to be synchronized as below picture. Now, as usual passing title,description to create event in calendar application, i use following code.
ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", title1);
values.put("allDay", 0);
values.put("dtstart", settime);
values.put("dtend", cal.getTimeInMillis()+60*60*1000);
values.put("description", desc1);
values.put("???????", mail_id);
values.put("???????", participant_mail_id);
values.put("visibility", 0);
values.put("hasAlarm", 1);
event = cr.insert(EVENTS_URI, values);
What should i use to pass the key to insert email id and participant id? Any Help is really appreciated. My screen shot goes below.
How to pass the mail id of the calendar that to be synchronized
The event is linked to a calendar by the "calendar_id". To get the "calendar_id" you should query for all the user's calendars and then search results for name in which you are interested. Here is a tutorial which should help: Working with the Android Calendar
Alternatively, you can create an event and then let the user choose to which Calendar the event should be added: Adding Calendar event through Intent
I want to view events over specific time range for a specific calendar, but am having trouble using the API, It is a generic API, and it reminds me of using the DOM. The problem is that it seems difficult to work with because much of the information is in generic base classes.
How do I get the events for a calendar using Groovy or Java?
Does anybody have an example of passing credentials using curl?
Example code would be appreciated.
This document has examples for most of the common use cases. For example, here's the code for retrieving events for a specific time range
URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/private/full");
CalendarQuery myQuery = new CalendarQuery(feedUrl);
myQuery.setMinimumStartTime(DateTime.parseDateTime("2006-03-16T00:00:00"));
myQuery.setMaximumStartTime(DateTime.parseDateTime("2006-03-24T23:59:59"));
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("jo#gmail.com", "mypassword");
// Send the request and receive the response:
CalendarEventFeed resultFeed = myService.query(myQuery, Feed.class);
You could make this a bit Groovier, using something like:
def myQuery = new CalendarQuery("http://www.google.com/calendar/feeds/default/private/full".toURL()).with {
minimumStartTime = DateTime.parseDateTime("2006-03-16T00:00:00");
maximumStartTime = DateTime.parseDateTime("2006-03-24T23:59:59");
it
}
def myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("jo#gmail.com", "mypassword");
// Send the request and receive the response:
def resultFeed = myService.query(myQuery, Feed);
If you do not need to alter the calendar, you only need to get the calendars private feed url, and you can use something like this (taken from the http://eu.gr8conf.org/agenda page). It uses the ICal4J library.
def url = "http://www.google.com/calendar/ical/_SOME_URL_/basic.ics".toURL()
def cal = Calendars.load(url)
def result = cal.components.sort { it.startDate.date }.collect {
def e = new Expando()
e.startDate = it.startDate.date
e.endDate = it.endDate.date
e.title = it.summary.value
if (it.location) {
e.presentation = Presentation.findByName(it.location.value, [fetch:"join"])
}
e.toString = {
"$startDate: $title"
}
return e
}
result
Happy hacking.