Contacts - how to distinguish between SIM, phone and other contacts?

只愿长相守 提交于 2019-12-08 03:20:42

问题


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?


回答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);


来源:https://stackoverflow.com/questions/30479059/contacts-how-to-distinguish-between-sim-phone-and-other-contacts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!