1

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)
    • EMPTY (Samsung Galaxy Alpha)
  • 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?

prom85
  • 16,896
  • 17
  • 122
  • 242

1 Answers1

1

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);
Logic
  • 2,230
  • 2
  • 24
  • 41
  • For the second part: SIM contacts not always seem to be named `com.anddroid.contacts.sim`. And I would have to exclude all other accounts like google as well, like whatsapp, viber and so on (would be possible but I don't know all apps that create contacts and every developer can save their contacts in the phone) – prom85 May 27 '15 at 11:02
  • Is it possible to get how SIM and local contacts should have in their ACCOUNT_TYPE field? – android developer May 15 '16 at 11:30