request Calendar Sync - Android Android OS

Android examples for Android OS:Calendar Contract

Description

request Calendar Sync

Demo Code


//package com.java2s;
import android.accounts.Account;
import android.accounts.AccountManager;

import android.content.ContentResolver;

import android.os.Bundle;
import android.provider.CalendarContract;

import android.accounts.Account;
import android.accounts.AccountManager;

import android.content.ContentResolver;

import android.os.Bundle;

import android.provider.CalendarContract;

public class Main {
    private static void requestCalendarSync(AccountManager aM) {
        Account[] accounts = new Account[0];
        try {/*from  w w  w  .j  a  va2s  .c  o m*/
            accounts = aM.getAccounts();
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (Account account : accounts) {
            int isSyncable = ContentResolver.getIsSyncable(account,
                    CalendarContract.AUTHORITY);

            if (isSyncable > 0) {
                Bundle extras = new Bundle();
                extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
                ContentResolver.requestSync(accounts[0],
                        CalendarContract.AUTHORITY, extras);
            }
        }
    }
}

Related Tutorials