gpt4 book ai didi

android - getContentResolver().delete 不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 10:45:48 25 4
gpt4 key购买 nike

我正在尝试删除特定联系人!我搜索了很多,但我尝试的每一个代码都不起作用!

public void delete(String name,String numero)
{
Cursor cur = getContentResolver().query(Contacts.CONTENT_URI,null, null, null, null);

while (cur.moveToNext())
{
try
{
String[] selectionArgs=new String[]{String.valueOf(numero)};
String lookupKey = cur.getString(cur.getColumnIndex(Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey);
getContentResolver().delete(uri, Phone.NUMBER +"=?", selectionArgs);
}
catch(Exception e)
{
System.out.println(e.getStackTrace());
}
}

我也试过这个而不是指定 selectionArgs 但什么都没有

getContentResolver().delete(uri, Contacts.DISPLAY_NAME +"="+ name, null);

并尝试用 ContactsContract.Contacts. 更改 Contacts. 但什么也没有但尝试使用联系人显示名称而不是号码删除。看来选择不行啊! uri 值是 Uri$HierarchicalUri 对吗?

有什么问题?

最佳答案

改变

getContentResolver().delete(uri, Contacts.DISPLAY_NAME +"="+ name, null);

String[] names = {name};
getContentResolver().delete(uri, Contacts.DISPLAY_NAME +"=?", names);

关于android - getContentResolver().delete 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24122701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com