如何使一个自定义帐户出现像谷歌/ LinkedIn / Facebook的本机联系人应用程序? [英] How to make a custom account show up like Google/LinkedIn/Facebook in the native Contacts app?

查看:179
本文介绍了如何使一个自定义帐户出现像谷歌/ LinkedIn / Facebook的本机联系人应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的一个应用程序,我们要去的地方是从我们自己的应用程序添加联系人,类似于LinkedIn怎么也连接和Facebook有朋友。因此,我们希望我们的自定义帐户,它显示在下面的图片(如的 MyAppName 的)与我们的应用程序添加联系人:

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:

我们现在有一个 SyncAdapter 从第一个图像看到,因为只希望这个联系人应用程序中显示。我们一直在寻找的文件,但找不到具体的事。

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".

推荐答案

在研究Budius的建议后,我终于想通了如何做到这一点。 这里是一个更precise链接地方它在文档中说明。基本上你只需要使你的帐户可见。除此之外,我发现对此处做答案。

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

所有赞扬code去亨利Pushel

这篇关于如何使一个自定义帐户出现像谷歌/ LinkedIn / Facebook的本机联系人应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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