如何创建一个SOURCE_ID引用一组? [英] How do I create a group with a source_id reference?

查看:129
本文介绍了如何创建一个SOURCE_ID引用一组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新

我终于想通这一个:
关键是要创建一个帐户名和帐户类型,这东西是不是真的明显看文档组(有与ContactsContract.Groups这些名字他们都在SyncColumns没有字段)。当您使用这两个值的组,同步过程中会产生SOURCE_ID你,这时你就可以利用组行ID或SOURCE_ID添加成员。

I finally figured this one out: The key is to create the group with an account name and account type, something that is not really apparent looking at the documentation (there are no fields with those name in ContactsContract.Groups they are in the SyncColumns). When you create the group with those two values, the sync process will generate the source_id for you, at which point you can add member using either the group row id or the source_id.

下面是一些示例code,如果有人需要它。

Here is some sample code if anyone needs it.

    ContentValues values = new ContentValues(); 
    values.put(ContactsContract.Groups.TITLE,"yourGroupName");
    values.put(ContactsContract.Groups.ACCOUNT_TYPE,"com.google");
    values.put(ContactsContract.Groups.ACCOUNT_NAME,"someuser@gmail.com");
    values.put(ContactsContract.Groups.GROUP_VISIBLE,1);
    context.getContentResolver().insert(ContactsContract.Groups.CONTENT_URI, values);

然后添加成员:

values = new ContentValues();
values.put(ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE,ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE);
values.put(ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID, 22);
//values.put(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID,  56);
// the above or 
values.put(ContactsContract.CommonDataKinds.GroupMembership.GROUP_SOURCE_ID,"sourceIdthatIsFilledInAfterSync");
//context.getContentResolver().insert(ContactsContract.Data.CONTENT_URI,values);

原题:
我一直在努力与相关的同步组成员的问题,并认为我想通了原因,但我不知道如何解决它。

Original question: I have been struggling with an issue related to syncing group memberships and think I figured out the cause, but I don't know how to fix it.

手动创建2组,一组通过code中的另一个,然后经过查询中使用这些列组。

After creating 2 groups , one via code the the other manually and then query the groups using these columns.

private final static String[] GROUP_COLUMNS = {
    ContactsContract.Groups._ID,
    ContactsContract.Groups.DATA_SET,
    ContactsContract.Groups.NOTES,
    ContactsContract.Groups.SYSTEM_ID,
    ContactsContract.Groups.GROUP_VISIBLE,
    ContactsContract.Groups.DELETED,
    ContactsContract.Groups.SHOULD_SYNC,
    ContactsContract.Groups.SOURCE_ID,
    ContactsContract.Groups.TITLE   
};

我可以转储出来的结果,因为这

I can dump out the results as this.

: --- begin ---
: key =  title , value = myNewTestGroup
: key =  data_set , value = null
: key =  _id , value = 45
: key =  sourceid , value = null
: key =  group_visible , value = 1
: key =  system_id , value = null
: key =  should_sync , value = 1
: key =  notes , value = myNewTestGroup
: key =  deleted , value = 0
: --- end ---

: --- begin ---
: key =  title , value = Mytest2
: key =  data_set , value = null
: key =  _id , value = 46
: key =  sourceid , value = 144c8b8d0cca8a52
: key =  group_visible , value = 1
: key =  system_id , value = null
: key =  should_sync , value = 1
: key =  notes , value = Mytest2
: key =  deleted , value = 0
: --- end ---

在手动创建组(Mytest2)具有被列为ContactsContract.SyncColumns列的souceid,而code组产生了空。

The manually create group (Mytest2) has a souceid which is listed as a column in ContactsContract.SyncColumns, while the code generated group has null.

我看到引用SOURCE_ID在可能的地方在android文档,但我看不出如何获得的。

I see references to source_id in may places in the android docs but I can't see how to obtain one.

我觉得不知怎的,我会得到这个,如果我的组与帐户相关联。
有谁知道如何在联想集团与帐户,或以其他方式得到这个源ID字段设置?

I think somehow i would get this if i associate the group with an account. Does anyone know how to associate at group with an account, or otherwise get this source id field set?

推荐答案

我终于想通这一个:关键是要创建一个帐户名和帐户类型,东西是不是真的明显组在看文档(有在ContactsContract.Groups这些名字他们在SyncColumns)没有字段。当您使用这两个值的组,同步过程中会产生SOURCE_ID你,这时你就可以利用组行ID或SOURCE_ID添加成员。

I finally figured this one out: The key is to create the group with an account name and account type, something that is not really apparent looking at the documentation (there are no fields with those name in ContactsContract.Groups they are in the SyncColumns). When you create the group with those two values, the sync process will generate the source_id for you, at which point you can add member using either the group row id or the source_id.

下面是一些示例code,如果有人需要它。

Here is some sample code if anyone needs it.

ContentValues values = new ContentValues(); 
values.put(ContactsContract.Groups.TITLE,"yourGroupName");
values.put(ContactsContract.Groups.ACCOUNT_TYPE,"com.google");
values.put(ContactsContract.Groups.ACCOUNT_NAME,"someuser@gmail.com");
values.put(ContactsContract.Groups.GROUP_VISIBLE,1);
context.getContentResolver().insert(ContactsContract.Groups.CONTENT_URI, values);

然后添加成员:

values = new ContentValues();
values.put(ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE,ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE);
values.put(ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID, 22);
//values.put(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID,  56);
// the above or 
values.put(ContactsContract.CommonDataKinds.GroupMembership.GROUP_SOURCE_ID,"sourceIdthatIsFilledInAfterSync");
context.getContentResolver().insert(ContactsContract.Data.CONTENT_URI,values);

这篇关于如何创建一个SOURCE_ID引用一组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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