2017-07-22 117 views
0

目前,我正在使用SubscriptionManager类API来检测SIM是否存在/不存在。 在单人SIM手机下方的方法工作从SIM卡读取联系人。从双SIM卡手机中的每张SIM卡分别读取联系人

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

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

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

回答

0

您可以使用ContactsContract 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); 

UPDATE

因为这没有工作,这意味着存储的ACCOUNT_TYPE的值并不如预期,可能像vnd.sec.contact.sim1vnd.sec.contact.sim2

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

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 
+0

我得到以下异常android.database.sqlite.SQLiteException:近 “”:语法错误(代码1):在编译:SELECT sort_key,send_to_voicemail,固定,sec_custom_alert,DISPLAY_NAME,display_name_alt AS phonetic_name_style FROM view_raw_contacts_restricted WHERE(1)AND((account_type = vnd.sec.contact.sim)) – Pause

+0

是的,我错过了选择值周围的撇号,现在修复 – marmor

+0

我试过你的解决方案,但没有运气。 选择= ACCOUNT_TYPE = 'vnd.sec.contact.sim' CUR = [email protected] I/System.out的:>>>>>倾倒光标[email protected] 我/系统.out:<<<<< – Pause

相关问题