android - 如何使用google contacts api以编程方式将手机联系人同步到android中的gmail

标签 android google-api sync android-contacts

如何使用 Google API 将 Android native 联系人同步到 Google 帐户。 提供一些有用的链接。

最佳答案

同步会自动发生。您可以通过编程方式添加或删除联系人。但是,当且仅当用户在手机设置中启用了“同步联系人”选项时,操作系统才会自动处理同步。

但是,如果用户使用如下方式启用了同步,则可以运行可以调用同步过程的同步例程:

private void requestSync()
{
    AccountManager am = AccountManager.get(this);
    Account[] accounts = am.getAccounts();

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

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

关于android - 如何使用google contacts api以编程方式将手机联系人同步到android中的gmail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12793568/

相关文章:

linux - Bash 脚本 : keep one line of local file in sync with remote file

安卓 : restart application after update - ACTION_PACKAGE_REPLACED

android - 如何处理 "javax.net.ssl.SSLHandshakeException",改造错误响应?

java - "org.xmlpull.v1.XmlPullParserException: expected: START_TAG"错误

javascript - Google 的 API javascript 示例中的脚本 async/defer/onload 用法

android - 如何知道同步何时完成?

Java 线程同步 - Thread.sleep() 方法未按预期工作

android - "Could not find method packageName()"RC1 错误 - flavor 不编译

javascript - CSV 文件未重新加载(Google GeoCharts)

react-native - Google API 在发布时无法工作(React-Native 应用程序),但在模拟器上正常工作(Expo)