如何为群组联系人Android创建自定义属性?

时间:2016-10-04 15:23:00

标签: android android-contentprovider android-contacts

我使用以下代码在Android中创建群组联系人。但是,它只提供两个属性:name和Id。我们可以为该组添加更多属性吗?如果可能,我们可以为组创建自定义属性,例如组的颜色吗?我们如何从添加的组中获取自定义属性。谢谢所有

public String createGroup(String name) {

            String[] GROUP_PROJECTION = new String[] { ContactsContract.Groups._ID,     ContactsContract.Groups.TITLE };

            try {
                ContentValues groupValues = null;
                ContentResolver cr = this.getContentResolver();
                groupValues = new ContentValues();
                groupValues.put(ContactsContract.Groups.TITLE, name);
                groupValues.put(ContactsContract.Groups.SHOULD_SYNC,true);
                cr.insert(ContactsContract.Groups.CONTENT_URI, groupValues);

            }
            catch(Exception e){
                Log.d("########### Exception :",""+e.getMessage());
                return "1";
            }

            String groupID = null;
            Cursor getGroupID_Cursor = null;
            getGroupID_Cursor = this.getContentResolver().query(ContactsContract.Groups.CONTENT_URI,  GROUP_PROJECTION, ContactsContract.Groups.TITLE+ "=?", new String[]{name}, null);

            getGroupID_Cursor.moveToFirst();
            groupID = (getGroupID_Cursor.getString(getGroupID_Cursor.getColumnIndex("_id")));

            return groupID;


        }

0 个答案:

没有答案