从双SIM卡手机中的每张SIM卡中单独读取联系人



目前我正在使用订阅管理器类 api 来检测 sim 是否存在。 在单SIM卡手机中,下面的方法可以从SIM卡读取联系人。

Uri simUri = Uri.parse("content://icc/adn/");
ContentResolver mContentResolver = this.getContentResolver();
Cursor c = mContentResolver.query(simUri, null, null, null, null);

我的应用程序是一个系统应用程序,并且具有root设备。 对于双SIM卡手机,如何单独读取每个SIM卡中的联系人。

如果有人能想到其他方法,他们非常受欢迎。我真的很感激这方面的任何帮助。

您可以使用联系人合同API的ACCOUNT_TYPE字段来查找SIM卡联系人。

您需要查询 RawContacts 表,以获取存储在 SIM 卡上的所有 RawContacts 的列表,并从该列表中获取联系人 ID。

String selection = RawContacts.ACCOUNT_TYPE + "='vnd.sec.contact.sim'";
Cursor cur = mContentResolver.query(RawContacts.CONTENT_URI, null, selection, null, null);
// cur should now contain all the requested contacts
DatabaseUtils.dumpCursor(cur);

更新

由于这不起作用,这意味着为ACCOUNT_TYPE存储的值与预期不符,可能类似于vnd.sec.contact.sim1vnd.sec.contact.sim2.

您可以创建一个测试方法来打印所有联系人的所有ACCOUNT_TYPEs 值,并使用该输出来确定所需的正确值。

HashSet<String> accountTypes = new HashSet<String>();
String[] projection = new String[] { RawContacts.ACCOUNT_TYPE };
Cursor cur = mContentResolver.query(RawContacts.CONTENT_URI, projection, null, null, null);
if (cur != null) {
while (cur.moveToNext()) {
accountTypes.add(cur.getString(0));
}
}
for (String type : accountTypes) {
Log.d("ACCOUNT_TYPE", type);
}
// Check the output in LogCat and look for `ACCOUNT_TYPE`s that look like `sim` types. then add those values to the selection of the above method

最新更新