gpt4 book ai didi

android - 如何使用联系人的 lookup_key 删除联系人

转载 作者:行者123 更新时间:2023-11-30 01:19:12 25 4
gpt4 key购买 nike

据我所知,使用 lookup_key 是删除联系人的最佳方式。每个联系人都有一个唯一的查找键,即使联系人已被编辑,例如按姓名或号码等删除...您可能会删除多个条目。

假设我的电话簿或 sim 卡中有联系人的 lookup_key :

String thelookupkey = 1393i2f.3789r504-2927292F4D4D2F35274949374B.2537i1272844629.1728i108

如何从我的电话簿中删除此联系人。我知道它类似于下面的内容,但不确定确切的语法(另外,不想在试验时破坏我的电话簿)

public void deletecontactbutton(View view) {
context.getContentResolver().delete(ContactsContract.Contacts.CONTENT_LOOKUP_URI,
null, thelookupkey);

}

最佳答案

我很自豪地说我写了(是的,我!!!)一个完全符合我要求的子例程:也就是说,使用 LOOKUP_KEY 删除联系人(电话、号码、与该联系人关联的所有详细信息)值(value):

public void deletecontactbutton(View view) {

String thelookupkey;
thelookupkey = "1885r1471-29373D3D572943292D4333";

// in our cursor query let's focus on the LOOKUP_KEY column
// this will give us all the strings in that column
String [] PROJECTION = new String [] { ContactsContract.Contacts.LOOKUP_KEY };

// we're going to query all the LOOKUP_KEY strings ; that is, the unique ids of all our contacts
// which we can find in the LOOKUP_KEY column of the CONTENT_URI table
Cursor cur = getContentResolver().query
(ContactsContract.Contacts.CONTENT_URI, PROJECTION, null, null, null);

try {
if (cur.moveToFirst()) {
do {
if
// If a LOOKUP_KEY value is equal to our look up key string..
(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)).equalsIgnoreCase(thelookupkey)) {
// then delete that LOOKUP_KEY value, including all associated details, like number, name etc...
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, thelookupkey);
getContentResolver().delete(uri, null, null);
}

} while (cur.moveToNext());
}
// deal with any errors, should they arise
} catch (Exception e) {
System.out.println(e.getStackTrace());
} finally {
// finally, close the cursor
cur.close();
}

}

关于android - 如何使用联系人的 lookup_key 删除联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37373313/

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