data & synchronization - manually sync mail. calen

2019-05-03 05:42发布

问题:

I am trying to write an app that syncs my mail and my calender with just a single click. After looking through this forum I found some good hints and wrote a short test app that takes my first google account and starts syncing.

The code is working so far but currently only the contacts were synced!

    AccountManager am = AccountManager.get(this);
    Account[] acc = am.getAccountsByType("com.google");
    Account account = null;
    if (acc.length > 0) {
        account = acc[0];

        Bundle extras = new Bundle();
        extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
        extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);

        ContentResolver.requestSync(account, ContactsContract.AUTHORITY,
                extras);
    }

The method requestSync takes "authority" as parameter and now I use "ContactsContract.AUTHORITY" and I guess that is the reason for only synching my contacts. My question now is, does anybody know what authority string I have to use to only sync my mail and calender? If "null" is used as authority all three (cal, contacts and mail) get synched

public static void requestSync (Account account, String authority, Bundle extras)

Thanks in advance!!

回答1:

OK, it seems the the Authority for contacts is:

"com.android.contacts"

and for calander:

"com.android.calendar"

But I could not find the String for syncing Gmail...