如何同步我们的应用程序联系人导入原生应用程序接触Android上编程 [英] How to sync our app contacts into native contact app on android programmatically

查看:312
本文介绍了如何同步我们的应用程序联系人导入原生应用程序接触Android上编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的应用我的联系人编程同步到原生的Andr​​oid应用程序的接触。请帮帮我。先谢谢了。

I want to sync my contacts from my app to native android contact app programmatically. Please help me. Thanks in advance.

推荐答案

您可以试试下面code帐户同步

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();
}

这篇关于如何同步我们的应用程序联系人导入原生应用程序接触Android上编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆