Chronogps
Chronogps

Reputation: 51

Android Calendar API : How to force sync for a specific calendar

I create a "secondary" calendar on https://calendar.google.com/calendar

After a few seconds it appears on my smartphone under Google Calendar App but if I want to see events, I have to go in Google Calendar (or S Planner with Samsung devices) settings, select the new calendar and activate Sync for this particular calendar to see his content, add / modify events.

How can I do this programmatically in my own app ? ContentResolver.setSyncAutomatically can only (de)activate sync for calendar in the global settings.

Thanks for your help.

Upvotes: 3

Views: 2182

Answers (1)

grebulon
grebulon

Reputation: 7982

Set the calendar to sync:

ContentResolver cr = activity.getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
values.put(CalendarContract.Calendars.VISIBLE, 1);
cr.update(
    ContentUris.withAppendedId(CalendarContract.Calendars.CONTENT_URI, calendarId),
    values, null, null);

Upvotes: 2

Related Questions