在 Android 上使用联系人组删除时出现问题
我有这段代码来删除联系人组,
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,但未执行删除,活动重新启动时我仍然在列表中看到该记录。 我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不需要添加 where 子句来说明这一点。
如果您不想立即删除数据库中的项目并且不将其标记为已删除,请将此行添加到您的 URI。
该标志:CALLER_IS_SYNCADAPTER 设置为 1 将立即删除行。
希望这有帮助。
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.
that flag: CALLER_IS_SYNCADAPTER set to 1 will delete row instantly.
Hope this helped.
这是我的失误:
在查询现有记录时,我必须添加一个 where 子句来表示我不想要
deleted=1
值,因为这些值不会立即删除,它们会被标记为已删除。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.您可以使用此删除联系人组
you can delete contact group using this