How to make a custom account show up like Google/LinkedIn/Facebook in the native Contacts app?

后端 未结 1 1597
死守一世寂寞
死守一世寂寞 2021-02-11 07:38

I\'m currently working on an application, where we are going to be adding contacts from our own application, similar to how LinkedIn has connections and Facebook has friends. Th

1条回答
  •  再見小時候
    2021-02-11 08:07

    After having studied Budius' suggestions, I finally figured out how to do it. Here is a more precise link to the place where it's stated in the documentation. Basically you just need to make your account visible. Other than that, I found the answer on how to do that here.

    ContentProviderClient client = getContentResolver().acquireContentProviderClient(ContactsContract.AUTHORITY_URI);
    ContentValues values = new ContentValues();
    values.put(ContactsContract.Groups.ACCOUNT_NAME, account.name);
    values.put(Groups.ACCOUNT_TYPE, account.type);
    values.put(Settings.UNGROUPED_VISIBLE, true);
    try
    {
       client.insert(Settings.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build(), values);
    }
    catch (RemoteException e)
    {
       e.printStackTrace();
    }
    

    All credit for this code goes to Henry Pushel.

    0 讨论(0)
提交回复
热议问题