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

元气小坏坏 提交于 2019-12-04 14:36:44

问题


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. Therefore we want our custom account, that is shown in the images below (as "MyAppName") with the contacts added from our application:

We currently have a SyncAdapter as seen from the first image, as just wish for this to be shown in the Contacts application. We've been looking at documentation, but couldn't find anything specific to this.

This is not about adding contacts, but getting the account to show up in the contacts application under "Accounts".


回答1:


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.



来源:https://stackoverflow.com/questions/15244334/how-to-make-a-custom-account-show-up-like-google-linkedin-facebook-in-the-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!