- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
据我所知,使用 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/
据我所知,使用 lookup_key 是删除联系人的最佳方式。每个联系人都有一个唯一的查找键,即使联系人已被编辑,例如按姓名或号码等删除...您可能会删除多个条目。 假设我的电话簿或 sim 卡中有联
在我的应用中,我想将联系人与其他数据相关联。对联系人的引用必须尽可能持久,否则关联的数据将变成垃圾。 首先,我应该使用 ContactsContract.Contact.LOOKUP_KEY 访问聚合
我必须从 Android 设备的联系人列表中选择一个联系人。 使用以下代码,我检索了一个包含设备上联系人列表的 Activity : Intent intent = new Intent(Intent
我正在修改我的应用程序以使用 LOOKUP_KEY 而不是 API 文档建议的 _ID 来存储联系人信息。我遇到的唯一问题是我无法再加载联系人的照片。 有问题的代码是这个: InputStream s
我是一名优秀的程序员,十分优秀!