On Android, how do you select only PHONE contacts?

I request Contacts from the built-in URI of the contact provider in Android. I want to get only PHONE contacts; is there a consistent way to do this? It seems from what I can find that the account name for telephone contacts differs from manufacturer to manufacturer (see this question ). Is there a way to get PHONE contacts (not SIM, Facebook, Twitter, or others) in a consistent, reliable, productive, and agnostic-hardware way?

+8
android android-contacts
source share
1 answer
Cursor cursor = null; try { String selection = ContactsContract.Data._ID + " = ?"; String[] selectionArgs = new String[] { id }; String[] projection = new String[] { ContactsContract.PhoneLookup.NUMBER}; cursor = getContentResolver().query( ContactsContract.Contacts.CONTENT_URI, projection, selection, selectionArgs, null); if (cursor == null || !cursor.moveToFirst()) return; String phone = cursor.getString(0); } finally { if (cursor != null && !cursor.isClosed()) try { cursor.close(); } catch (Throwable ignore) { // Ignored. } } 

Where is the "?" this is a user id, you can put this code in a loop.

-one
source share

All Articles