希望以编程方式创建联系人新组 [英] Want to create a new group in contacts programmatically

查看:100
本文介绍了希望以编程方式创建联系人新组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个新的联系人组。我可以查询组和显示所有的组名,但我不能在Android中创建一个组,我想作为创建联系人的方法,但不能创建...

  ContentResolver的CR = this.getContentResolver();
    groupValues​​ =新ContentValues​​();
    Log.e(本集团,开始);
    groupValues​​.put(android.provider.Contacts.GroupMembership.GROUP_ID,4);
    groupValues​​.put(android.provider.Contacts.GroupMembership.NAMESriseshaa);
    groupValues​​.put(android.provider.Contacts.GroupMembership.PERSON_ID,1);

    cr.insert(android.provider.Contacts.GroupMembership.CONTENT_URI,groupValues​​);
 

解决方案

我发现answer.i发现有两种方式,但我不知道这是正确的,或者use.i我在这里分享的最好方式。

其如添加联系人简单的方法,

  ContentValues​​ groupValues​​;
创建组()
{
 ContentResolver的CR = this.getContentResolver();
 groupValues​​ =新ContentValues​​();
 groupValues​​.put(ContactsContract.Groups.TITLEMyContactGroup);
 cr.insert(ContactsContract.Groups.CONTENT_URI,groupValues​​);
}
 

使用ContentProviderOperation另一种方法

 私人无效createGroup(){
    ArrayList的< ContentProviderOperation> OPS =新的ArrayList< ContentProviderOperation>();

    ops.add(ContentProviderOperation
            .newInsert(ContactsContract.Groups.CONTENT_URI)
            .withValue(ContactsContract.Groups.TITLE,社会责任投资)建())。
    尝试 {

        。getContentResolver()applyBatch(ContactsContract.AUTHORITY,OPS);

    }赶上(例外五){
        Log.e(错误,e.toString());
    }

}
 

感谢

I want to create a new contact group. I can query the group and display all the group names but I can't create a group in android I tried as creating contacts method but not created...

ContentResolver cr = this.getContentResolver();
    groupValues = new ContentValues();
    Log.e("Group","start");
    groupValues.put(android.provider.Contacts.GroupMembership.GROUP_ID, 4);
    groupValues.put(android.provider.Contacts.GroupMembership.NAME, "Sriseshaa");
    groupValues.put(android.provider.Contacts.GroupMembership.PERSON_ID, 1);

    cr.insert(android.provider.Contacts.GroupMembership.CONTENT_URI, groupValues);

解决方案

i found the answer.i found in two ways but i dont know which is correct or best way to use.i am sharing those here..

its simple way like adding contact,

ContentValues groupValues;
create group()
{
 ContentResolver cr = this.getContentResolver();
 groupValues = new ContentValues();
 groupValues.put(ContactsContract.Groups.TITLE, "MyContactGroup");
 cr.insert(ContactsContract.Groups.CONTENT_URI, groupValues);
}

Another method using ContentProviderOperation

 private void createGroup() {
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

    ops.add(ContentProviderOperation
            .newInsert(ContactsContract.Groups.CONTENT_URI)
            .withValue(ContactsContract.Groups.TITLE, "SRI").build());
    try {

        getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);

    } catch (Exception e) {
        Log.e("Error", e.toString());
    }

}

Thanks

这篇关于希望以编程方式创建联系人新组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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