How to get all android contacts but without those which are on SIM
Asked Answered
P

1

13

It is possible to do it in one query?

As far as I know content uri of sim contacts is content://icc/adn

Partnership answered 2/12, 2010 at 18:38 Comment(1)
Please Checkout a library on Github to fetch contacts with simple easy to use api.Honeydew
P
21

This is very easy! :)

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);
Partnership answered 10/12, 2010 at 13:53 Comment(5)
Can you please write the code of how to get the number and name from this cursor. i hvae write the code as "while(cursor.moveToNext()){String phoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); Log.i("all contacts",phoneNumber+"->"+name); }Likely
but got the error like ": Bad request for field slot 0,-1. numRows = 46, numColumns = 2Likely
'com.anddroid.contacts.sim' is a manual value. There is any constant refer to it.Anaphylaxis
@Anaphylaxis How do you know which possible constants are available for the current device? Is there a way to get the correct one for SIM/local storage of contacts, no matter the device?Couscous
sorry I dont know the constantAnaphylaxis

© 2022 - 2024 — McMap. All rights reserved.