联系人-如何区分SIM卡,电话和其他联系人? [英] Contacts - how to distinguish between SIM, phone and other contacts?
问题描述
我正在从手机中读取所有联系人,如下所示:
I'm reading ALL contacts from the phone like following:
Cursor cursor = MainApp.get().getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
null,
null,
null,
ContactsContract.Data.CONTACT_ID + " ASC");
我从联系人中读取ContactsContract.Data.ACCOUNT_TYPE_AND_DATA_SET
和ContactsContract.RawContacts.ACCOUNT_NAME
并进行了分析,因为我想区分电话,SIM卡和其他任何联系人...但是我只能看到这些值是特定于电话的.
I read ContactsContract.Data.ACCOUNT_TYPE_AND_DATA_SET
and ContactsContract.RawContacts.ACCOUNT_NAME
from the contacts and analysed them because I want to distinguish between phone, sim and any other contact... But I only can see that the values are very phone specific.
1)我目前仅知道ContactsContract.Data.ACCOUNT_TYPE_AND_DATA_SET
的以下值:
1) I currently only know following values for ContactsContract.Data.ACCOUNT_TYPE_AND_DATA_SET
:
-
电话联系人
Phone contacts
-
com.sonyericsson.localcontacts (Sony Xperia S)
-
vnd.sec.contact.phone (Samsung Galaxy Alpha)
com.sonyericsson.localcontacts (Sony Xperia S)
vnd.sec.contact.phone (Samsung Galaxy Alpha)
SIM卡联系人
-
com.sonyericsson.adncontacts (Sony Xperia S)
-
vnd.sec.contact.sim (Samsung Galaxy Alpha)
com.sonyericsson.adncontacts (Sony Xperia S)
vnd.sec.contact.sim (Samsung Galaxy Alpha)
2)我目前仅知道ContactsContract.Data.ACCOUNT_NAME
的以下值:
2) I currently only know following values for ContactsContract.Data.ACCOUNT_NAME
:
-
电话联系人
Phone contacts
-
Phone contacts
(Sony Xperia S) - 空(三星Galaxy Alpha)
Phone contacts
(Sony Xperia S)- EMPTY (Samsung Galaxy Alpha)
SIM卡联系人
-
SIM contacts
(Sony Xperia S) -
primary.sim.account_name
(三星Galaxy Alpha)
SIM contacts
(Sony Xperia S)primary.sim.account_name
(Samsung Galaxy Alpha)
Google,WhatsApp,Viber联系人很容易识别,但是如何找出联系人是所有电话(或至少大多数电话)上的电话联系人或SIM卡联系人?
Google, WhatsApp, Viber contacts are easy to recognise, but how to find out it a contact is a phone contact or a sim contact on all phones (or at least on most)?
我不想为SIM卡联系人显示"vnd.sec.contact.sim",而是要显示"SIM".
I don't want to display "vnd.sec.contact.sim" for sim contacts but want to display "SIM" instead.
有人知道我列表中的其他字符串吗? 还是有人知道更好的解决方案?
Does anyone know other strings for my list? Or does anyone know a better solution?
推荐答案
要从SIM卡获取联系人,请使用以下方法:
To get contacts from SIM use this:
Uri simUri = Uri.parse("content://icc/adn");
Cursor cursorSim = this.getContentResolver().query(simUri, null, null,null, null);
while (cursorSim.moveToNext()) {
listName. add(cursorSim.getString(cursorSim.getColumnIndex("name")));
listContactId. add(cursorSim.getString(cursorSim.getColumnIndex("_id")));
listMobileNo. add(cursorSim.getString(cursorSim.getColumnIndex("number")));
}
姓名,_id,号码是SIM卡联系人表中的字段
name, _id, number are fields in SIM contacts table
供电话中的联系人使用
Cursor cursor = mContentResolver.query(
RawContacts.CONTENT_URI,
new String[]{RawContacts._ID,RawContacts.ACCOUNT_TYPE},
RawContacts.ACCOUNT_TYPE + " <> 'com.anddroid.contacts.sim' "
+ " AND " + RawContacts.ACCOUNT_TYPE + " <> 'com.google' " //if you don't want to google contacts also
,
null,
null);
这篇关于联系人-如何区分SIM卡,电话和其他联系人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!