Android: Enable imported account contacts programmatically

后端 未结 1 1823
情深已故
情深已故 2020-12-19 16:56

I\'m successfully importing external contacts into the newly created account using this tutorial. The account is setup to re-sync programmatically and yet, to be able to see

相关标签:
1条回答
  • 2020-12-19 17:11

    i had the same problem and solved it with following code via account creation:

    mAccountManager.addAccountExplicitly(account, mPassword, null);
    // Set contacts sync for this account.
    ContentResolver.setSyncAutomatically(account,
    ContactsContract.AUTHORITY, true);
    ContentProviderClient client = getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY_URI);
    ContentValues cv = new ContentValues();
    cv.put(Groups.ACCOUNT_NAME, account.name);
    cv.put(Groups.ACCOUNT_TYPE, account.type);
    cv.put(Settings.UNGROUPED_VISIBLE, true);
    try {
    client.insert(Settings.CONTENT_URI.buildUpon()                  .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true")
    .build(), cv);
    } catch (RemoteException e) {...}
    
    0 讨论(0)
提交回复
热议问题