开发者

How to add contacts directly to a group without creating an account?

I have this contacts that needs to be imported directly to a particular group that i created in which AFAIK that adding of conta开发者_运维百科cts in an Account ,in the api seems to be broken(can't add other fields) so i implemented my own Activity to add accounts.

how do i add them directly to a group?


If you're talking about android 2.x, then groups exist on a per account basis. You need to first add your contact to an account before you can add it to a group.

You can add it to the default "device" account instead of a synced account if you know the account type/name for that device. These values are different for every maker I've tried writing code for. You should be able to get a list of these values from the accountmanager class. Null for both values appears to work on the nexus one, but fails spectacularly on every other phone I've tried.

These general steps should work:

  1. Create your new raw contact in the same account your group will be in
  2. Save the contact (and let it sync)
  3. Create Your group for that same account in the group table (if it doesn't exist)
  4. Add your synced contact to that new group by creating an entry in the groupmembership table (this is the data table, using the groupmembership mimetype).
  5. Let the group sync.

Caution: As of at least android 2.1, before you can add new contacts to a new group, you must add an existing (synced) contact to it first. If you do not and add new, unsynced contacts to a newly created, empty group, these contacts will disappear from the phone on the next sync and will not appear on the server (you'll lose the data). I'm not sure if this is a bug or just a limitation of the current group implementation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜