Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view a public Google Calendar via an Android Application

I must've gone through ever Stack Overflow question based on the Google Calendar so far with no luck what so ever. I've been trying this for hours now and got little to no results at all.

I'm a pretty new programmer with Java and Android, with quite little experience out of the field as it is. Basically the main problem I am having is with viewing another user's Google Calendar which is set to public.

At the moment, from the Google tutorials and other sites I've managed to get the calendar showing, which is pretty simple enough. It'll just load up and show the current user's calendar. Which can literally be done with (with a simple button in the layout).

    public void onClick(View view) {
    // A date-time specified in milliseconds since the epoch.
    long startMillis = System.currentTimeMillis();

    Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
    builder.appendPath("time");
    ContentUris.appendId(builder, startMillis);
    Intent intent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
    startActivity(intent);
}

Obviously this doesn't pass in any user data for the public account or anything, I've been reading through the Calendar Provider Developer guides within the Google tutorials. I've tried to set up the account details thing, but it just never works. I've tried to do it as a Sync Adapter, but honestly I just know I'm not doing it right. I don't know if I really even need to use a Sync Adapter as all I want to do is literally see the events, not modify anything or update anything.

I am using API 14+ and want to user the Calendar Provider etc. It looks simple enough but I've been bashing my head against this for a few days and put a lot of hours into it and seemingly nothing I do works. At least I've got some sort of calendar opening but it's not what I want.

Is it all just down to the sync adapter? If so how will I be able to call a calendar? Another question similar had

private static Uri buildCalUri() {
return CalendarContract.Calendars.CONTENT_URI
        .buildUpon()
        .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
        .appendQueryParameter(Calendars.ACCOUNT_NAME, ACCOUNT_NAME)
        .appendQueryParameter(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL)
        .build();

}

I'm hoping this is something similar to what I need but I'm very unsure. In the developer tutorial ACCOUNT_TYPE_LOCAL was important if the account wasn't on the device

Any help will be greatly appreciated!

like image 658
Jamibi Avatar asked Feb 09 '14 22:02

Jamibi


1 Answers

If you are looking to integrate the public Google Calendar (www.google.com/calendar) with your Android Application, you have to use the Google Calendar API.

The easiest method would be download the Google Calendar Client Library from here and then use the API Reference here. In the Client Library Page, you want to download "Google APIs Client Library for Java (rc)" package to integrate into your Android App.

You will first need to go to API Console to create an App with Calendar API Access .

If you do not want to use the native library, you can even do it using REST API (use HTTP GET & POST Commands), example App here

Hope this helps.

like image 181
user1406716 Avatar answered Nov 02 '22 06:11

user1406716