Note that there are some explanatory texts on larger screens.

plurals
  1. POGet Contacts mobile number only
    primarykey
    data
    text
    <p>There have been several questions on SO regarding getting Contacts numbers using the Contacts API but I'd like to know if there is a way to identify that the number retrieved is a mobile number.</p> <p>The following code is often shown as a way to get a Contact's phone numbers, as it gets a list of one or more phone numbers:</p> <pre><code>String[] projection = {ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.HAS_PHONE_NUMBER}; String selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1"; Cursor cursor = null; Cursor phones = null; try { cursor = managedQuery(intent.getData(), projection, selection, null, null); while (cursor.moveToNext()) { String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)); phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null); while (phones.moveToNext()) { String pdata = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA)); Log.v("DATA",pdata); } } } catch (NullPointerException npe) { Log.e(TAG, "Error trying to get Contacts."); } finally { if (phones != null) { phones.close(); } if (cursor != null) { cursor.close(); } } </code></pre> <p>Whilst, this works okay, is there any way to easily identify that the phone number is a mobile type (apart from trying to pattern match with Regex).</p> <p>I suspect there must be a related piece of data, so that native apps can classify the phone number - as in the picture below:</p> <p><img src="https://i.stack.imgur.com/ujg7E.jpg" alt="Phone types in Contact info"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload