【发布时间】:2021-01-22 01:54:07
【问题描述】:
我想创建一个可以恢复已删除联系人的应用。它适用于所有其他设备,但在 android 10 中,应用程序无法获取已删除的联系人。有没有办法从android 10中获取已删除的联系人。
这是我的代码,可以恢复已删除的联系人
public static final String WHERE_MODIFIED1 = "( " + ContactsContract.RawContacts.DELETED + "=1)";
ContentResolver cr = getContentResolver();
Cursor cur = cr.query((ContactsContract.RawContacts.CONTENT_URI),
null, WHERE_MODIFIED1, null, (DeletedContactRecovery.hasHoneycomb() ? "sort_key" : "display_name") + " COLLATE LOCALIZED ASC");
assert cur != null;
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String phone = null;
//if (!(Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0)) {
System.out.println("name : " + name + ", ID : " + id);
// get the phone number
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{id}, null);
assert pCur != null;
while (pCur.moveToNext()) {
phone = pCur.getString(
pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
System.out.println("phone" + phone);
}
pCur.close();
//}
if (id != null) {
contactList.add(new Contact(name, phone, id));
}
Log.e("hvy", "onCreaterrView Phone Number: name = " + name
+ " No = " + phone);
}
}
cur.close();
【问题讨论】:
标签: android android-studio contacts android-contacts