Reputation: 17878
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");
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) 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)
SIM contacts
com.sonyericsson.adncontacts (Sony Xperia S)
vnd.sec.contact.sim (Samsung Galaxy Alpha)
2) I currently only know following values for ContactsContract.Data.ACCOUNT_NAME
:
Phone contacts
Phone contacts
(Sony Xperia S)SIM contacts
SIM contacts
(Sony Xperia S)primary.sim.account_name
(Samsung Galaxy Alpha)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)?
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?
Upvotes: 1
Views: 5920
Reputation: 2258
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")));
}
name, _id, number are fields in SIM contacts table
And for the contacts from phone use
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);
Upvotes: 1