无法删除gmail联系人组android

时间:2014-02-20 10:57:30

标签: android gmail sync android-contacts

我一直在尝试使用此代码删除所有联系人组

private void deletaAllInGroup(Context context, long groupId)
           throws RemoteException, OperationApplicationException{
    ContentValues values = new ContentValues();         
    values.put(ContactsContract.Groups._ID, groupId);
    getContentResolver().delete(ContactsContract.Groups.CONTENT_URI,values.toString(),null);
        }

它是否成功删除了那些属于手机群组但该代码没有删除gmail联系人组怎么做?

1 个答案:

答案 0 :(得分:1)

我这样解决这个问题

ArrayList<GroupNameDetails> stateList = new ArrayList<GroupNameDetails>();
      final String[] GROUP_PROJECTION = new String[] 
                {
                    ContactsContract.Groups._ID, ContactsContract.Groups.TITLE,   ContactsContract.Groups.ACCOUNT_TYPE//this line will do the trick
                };
            Cursor cursor = getContentResolver().query(ContactsContract.Groups.CONTENT_URI, GROUP_PROJECTION, null,
                    null, ContactsContract.Groups.TITLE);
            while (cursor.moveToNext()) {
                String accountname=cursor.getString(cursor.getColumnIndex(ContactsContract.Groups.ACCOUNT_TYPE));
                Toast.makeText(getBaseContext(), accountname, Toast.LENGTH_LONG).show();// and it will display group type
                String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Groups._ID));
                Log.v("Test", id);
                //ContactsContract.Groups.ACCOUNT_NAME

                String gTitle = (cursor.getString(cursor.getColumnIndex(ContactsContract.Groups.TITLE)));
                if(favGroupName.contains(gTitle)==false)
                {
                favGroupId.add(id);
                favGroupName.add(gTitle);

                GroupNameDetails _states = new GroupNameDetails(Long.parseLong(id),gTitle, false);
                stateList.add(_states);
                }
                Log.v("Test", gTitle);
                if (gTitle.contains("Favorite_")) {
                    gTitle = "Favorites";

                }

            }