【问题标题】:How to sync our app contacts into native contact app on android programmatically如何以编程方式将我们的应用程序联系人同步到 android 上的本机联系人应用程序
【发布时间】:2012-09-24 08:46:10
【问题描述】:

我想以编程方式将我的联系人从我的应用程序同步到本机 android 联系人应用程序。请帮我。提前致谢。

【问题讨论】:

  • “我想将我的应用程序中的联系人同步到.....”你的应用程序中如何有联系人??
  • 如果您有一些号码要存储在联系人中...这里就是答案...stackoverflow.com/questions/4744187/…
  • 我必须将我的联系人与我选择的铃声同步

标签: android sync android-contacts


【解决方案1】:

您可以尝试以下代码进行帐户同步

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-29
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多