android - 如何以编程方式在android 10中恢复已删除的联系人
问题描述
我想创建一个可以恢复已删除联系人的应用程序。它适用于所有其他设备,但在 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 应用程序,有必要将其设为默认 Dailer 或 SMS 应用程序。当我厌倦阅读 android 10 中的阻止联系人时,我曾经遇到过同样的问题,即使我的应用程序在 android 10 下运行良好。我不知道这里的解决方案到底是什么,但尝试将应用程序设为默认值,然后尝试阅读联系人。
推荐阅读
- python - 姜戈| 一页上有多个表单 - 按下了哪些按钮
- javascript - Javascript对象数组,基于部分字符串或子字符串搜索匹配
- c++ - 理解 GCC 中的 std::pow 实现
- html - 下拉菜单无法正常工作
- python - 如何在具有个人功能的子图中绘图?
- activemq-artemis - Artemis 核心 API 使用的好例子
- python - 根据 Pandas DF 中每行的条件获取列标题列表
- sql-server - 创建新表,语法错误
- python - 使用 PyPng 转换图像的位深度
- python - 为什么来自机器人的消息的反应列表不显示在终端中?