在安卓系统上使用联系组删除的问题[英] Issue using Contact Group delete on Android

本文是小编为大家收集整理的关于在安卓系统上使用联系组删除的问题的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有此代码删除联系人组

public void delete(Activity act,String[] args) {
        try {
            int b=act.getContentResolver().delete(ContactsContract.Groups.CONTENT_URI,"_ID=?", args);

            Toast.makeText(act, "Deleted",Toast.LENGTH_SHORT).show();


            //notify registered observers that a row was updated
            act.getContentResolver().notifyChange(ContactsContract.Groups.CONTENT_URI, null);

        } catch (Exception e) {
            Log.v(TAG, e.getMessage(), e);
            Toast.makeText(act, TAG + " Delete Failed",Toast.LENGTH_LONG).show();
        }
    }

我称之为

的方法
private void processDelete(long rowId) {
        String[] args = { String.valueOf(rowId) };

        objItem.delete(this, args);
        cur.requery();
    }

我有

<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>

ID通过确定.

b值返回1,但是未执行删除,在活动重新启动时,我仍然在列表中看到记录. 我做错了什么?

推荐答案

这是我的错过:

当qu quat quat the现有记录时,我必须添加一个条款来表示我不需要deleted=1值,因为这些值未立即删除,因此将其标记为已删除.

Cursor managedCursor = act.managedQuery(contacts, projection, 
                ContactsContract.Groups.DELETED + "=0", 
                null,
                ContactsContract.Groups.TITLE + " ASC");
        return managedCursor;

其他推荐答案

您不需要添加在哪里说的条款. 如果您不会在数据库中立即删除项目而不将其标记为已删除,请将此行添加到您的URI.

mUri.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER,"1").build();
//and then call your delete function with URI appended like this.
mResolver.delete(mUri,null, null);

该标志:caller_is_syncadapter设置为1,将立即删除行.

希望这有所帮助.

其他推荐答案

您可以使用此

删除联系人组
    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);
        }

本文地址:https://www.itbaoku.cn/post/102750.html

问题描述

I have this code to delete a Contact Group

public void delete(Activity act,String[] args) {
        try {
            int b=act.getContentResolver().delete(ContactsContract.Groups.CONTENT_URI,"_ID=?", args);

            Toast.makeText(act, "Deleted",Toast.LENGTH_SHORT).show();


            //notify registered observers that a row was updated
            act.getContentResolver().notifyChange(ContactsContract.Groups.CONTENT_URI, null);

        } catch (Exception e) {
            Log.v(TAG, e.getMessage(), e);
            Toast.makeText(act, TAG + " Delete Failed",Toast.LENGTH_LONG).show();
        }
    }

I call the method like

private void processDelete(long rowId) {
        String[] args = { String.valueOf(rowId) };

        objItem.delete(this, args);
        cur.requery();
    }

I have

<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>

The ID is passed ok.

The b value returns 1, but the delete is not performed, on activity restart I still see the record in the list. What I am doing wrong?

推荐答案

It was my miss:

When quering the existing records I had to add a where clause to denote that I do not want deleted=1 values, as the values are not delete instantly, they are flagged as deleted.

Cursor managedCursor = act.managedQuery(contacts, projection, 
                ContactsContract.Groups.DELETED + "=0", 
                null,
                ContactsContract.Groups.TITLE + " ASC");
        return managedCursor;

其他推荐答案

You don't need to add where clause saying that. If you wont to instantly delete items in database and not flag them as deleted, add this row to you URI.

mUri.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER,"1").build();
//and then call your delete function with URI appended like this.
mResolver.delete(mUri,null, null);

that flag: CALLER_IS_SYNCADAPTER set to 1 will delete row instantly.

Hope this helped.

其他推荐答案

you can delete contact group using this

    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);
        }