简体   繁体   English

如何以编程方式将我们的应用程序联系人同步到android上的本机联系人

[英]How to sync our app contacts into native contact app on android programmatically

I want to sync my contacts from my app to native android contact app programmatically. 我想以编程方式将我的应用程序中的联系人同步到本机android联系人应用程序。 Please help me. 请帮我。 Thanks in advance. 提前致谢。

you can try below code for account syncing 您可以尝试以下代码进行帐户同步

public static void requestSyncNow(final Context context) {

    new Thread(new Runnable() {
        @Override
        public void run() {
            AccountManager accountManager = AccountManager.get(context);
            Account[] accounts = accountManager.getAccounts();
            boolean isMasterSyncOn = ContentResolver.getMasterSyncAutomatically();


            for (Account account : accounts) {
                Log.d(TAG, "account=" + account);

                int isSyncable = ContentResolver.getIsSyncable(account,
                        ContactsContract.AUTHORITY);
                boolean isSyncOn = ContentResolver.getSyncAutomatically(account,
                        ContactsContract.AUTHORITY);
                Log.d(TAG, "Syncable=" + isSyncable + " SyncOn=" + isSyncOn);
                if (isSyncable > 0 /* && isSyncOn */) {
                    Log.d(TAG, "request Sync");
                    Bundle bundle = new Bundle();
                    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
                    ContentResolver.requestSync(account, ContactsContract.AUTHORITY, bundle);
                }
            }

        }
    }, "SyncLauncher").start();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在android中以编程方式添加铃声到本机应用程序联系人 - How to add ringtone to native app contacts programmatically in android 如何将我的 Flutter 应用程序联系人链接到 android 的本机联系人应用程序? - How to link my Flutter App contacts to android's native contact application? Android-如何像在本机应用程序中检索联系人列表? - Android - How to retrieve contacts list as in native app? 如何在Android上的本机联系人应用程序中将您的应用程序集成到QUICK CONTACT中? - How to integrate your app in QUICK CONTACT on the native contact app on android? 如何以编程方式将我的应用程序设置为 android 中的联系人默认应用程序 - How to set my app as contacts default app in android programmatically 从Android联系人应用程序获取联系人数量 - Fetching number of Contacts from android contact app Android通过应用提供/同步联系人 - Android provide/sync contacts from app 如何在Android中添加联系人,例如Skype,本机联系人应用中的whatsapp? - How to add contact in Android like skype, whatsapp in native contact app? 如何在Android上联系应用程序? - How to Contacts App on Android? 如果我从本机 android 应用程序读取联系人,我是否应该获得 READ_CONTACTS 权限? - Should I have permission READ_CONTACTS if I read contact from native android app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM