由网友(骚年求逆推i)分享简介:我想创建一个新的联系人组。我可以查询组和显示所有的组名,但我不能在Android中创建一个组,我想作为创建联系人的方法,但不能创建... ContentResolver的CR = this.getContentResolver();groupValues =新ContentValues();Log.e(本集团,...
我想创建一个新的联系人组。我可以查询组和显示所有的组名,但我不能在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
相关推荐
最新文章