如何将联系人组添加到联系人管理器示例应用程序中?

发布于 2024-10-08 03:22:20 字数 210 浏览 0 评论 0原文

我正在从 Android SDK 运行 Contact Manager 示例应用程序。当我将联系人添加到 Gmail 帐户时,它会被添加为“隐形联系人”。我假设这是因为我没有告诉联系人应该将其分配到哪个“组”。我在网上查了几天,却空手而归。

我真正想做的是将联系人添加到我选择的联系人帐户中,并将该联系人与所选 Gmail 帐户中的联系人组相关联,以便该联系人的信息将显示在用户的联系人中。

I am running the Contact Manager sample app from the Android SDK. When I add a contact to my Gmail account, it gets added as an 'invisible contact'. I am assuming this is because I am not telling the contact which 'group' it should be assigned to. I have been looking around the internet for a few days and have come up empty handed.

What I really want to do is add the contact to the Contact Account that I select and have the contact associated with a Contact Group within the selected Gmail Account, so the contact's info will be displayed in the user's contacts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挽梦忆笙歌 2024-10-15 03:22:21

要使其与新的 ContactsContract API 一起使用,您可以将其添加到 ContentProviderOperation 列表中:

ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE,
                    ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID, 1)
            .build());

To make it work with the new ContactsContract API, you can add this to the ContentProviderOperation list:

ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE,
                    ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID, 1)
            .build());
彩虹直至黑白 2024-10-15 03:22:21

您的目标 Android 版本是什么?您当然知道联系人 API 在 2.x 中发生了根本性的变化...

我遇到了隐形联系人的确切问题,但仅在 1.x 上。我发现解决方案是添加到内置的“我的联系人”组:

// Add to the My Contacts group
ContentValues values = new ContentValues();
values.put(GroupMembership.PERSON_ID, contact.mAndroidId); 
values.put(GroupMembership.GROUP_ID, 1); // 1 is always the ID of the built-in "My Contacts" group 
activity.getContentResolver().insert(GroupMembership.CONTENT_URI,values);

如果您想添加到特定的用户定义组而不是“我的联系人”,您将需要从 Contacts.Groups 表。

What version of Android are you targeting? You are of course aware that the Contacts API changed radically in 2.x...

I hit this exact problem of invisible contacts, but only on 1.x. I found the solution was to add to the built-in "My Contacts" group :

// Add to the My Contacts group
ContentValues values = new ContentValues();
values.put(GroupMembership.PERSON_ID, contact.mAndroidId); 
values.put(GroupMembership.GROUP_ID, 1); // 1 is always the ID of the built-in "My Contacts" group 
activity.getContentResolver().insert(GroupMembership.CONTENT_URI,values);

If you want to add to a specific user-defined group rather than My Contacts you will need to fish the right GROUP_ID out of the Contacts.Groups table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文