Google calendar: how to access it on android
What would be the best way to acces the google calendar on android right now?
I found the following ways:
google-api-java-client - It's only an alpha. Authenticating, getting calendar list works, but updating calendar crashes in sample. +no documentation and bad sample codes anyway.
hackity hack reverse engeneering - Sounds bad, also, (propably) not futureproof.
Google data api - As far as I know, it does not support/work on android.
开发者_C百科Are there any alternatives that I have missed? Are there any working examples out there?
I recently used SignPost for this. It handles OAuth, and you can use it to sign your HTTP requests to get or post data to your calendars. I had trouble getting Google's Java API to work with Android since I think it relies on Java APIs that are not necessarily present in Android.
To make your requests, you can refer to this page: http://code.google.com/apis/calendar/data/2.0/developers_guide_protocol.html
Have you looked at the Data API Developer's Guide: Java? You can also work directly with HTTP request/response, if things you want/need aren't supported in the Java API.
I haven't personally used the Java API, but I have worked directly with HTTP, and found it to be pretty straightforward.
I think that this is a well known issue, but not so well clear yet. Looking at all the questions and answer provided it seems that you have two options:
Use the hacks you were refering in your answer (not suggested at all, because as you said there is no guarantee that the same trick will work in future). Some updates have been made in order to make it works even under froyo, see here.
Use this http://code.google.com/p/google-api-java-client/. Quoting from the project description on the website
Written by Google, this library is a flexible, efficient, and powerful Java client library for accessing any HTTP-based API's on the web. It is the recommended library for accessing Google API's based on REST or JSON-RPC.
`
Include these(Calendar-2.1,client 1.0,core 1.0) jar files from gdata api and include two external jar files in our application.. Those two files (guava-11.0.2 and jsr305 ) are available in deps folder of gdata
and this code for retrive events from calendar
Declare globally your calendar id and password
you can reach to me on facebook by using this address on facebook.com/rajivbawa22 for more tutorials
String userName = "example@gmail.com"; // put here your gmail id
String userPassword = "12345-example ";// put here your gmail password
but make sure you have account in gmail as well as in google calendar
try {
CalendarService myService = new CalendarService("com.demo.calendar");
myService.setUserCredentials(userName, userPassword);
// Send the request and print the response
URL feedUrl = new URL(
"https://www.google.com/calendar/feeds/"+userName+"/private/full");
// "https://www.google.com/calendar/feeds/default/owncalendars/full");
Log.e("", "Calendar1========");
CalendarFeed resultFeed = myService.getFeed(feedUrl,
CalendarFeed.class);
Log.e("", "Calendar2*********" + resultFeed);
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
Log.e("", "========" + resultFeed.getEntries().size());
CalendarEntry entry = resultFeed.getEntries().get(i);
Log.e("", "**********" + entry.getTitle().getPlainText());
}
} catch (Exception e) {
e.printStackTrace();
}
see result in logs and give yours feedbacks
精彩评论