Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>private void getDetails(){ Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; ContentResolver cr = getContentResolver(); Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null); String[] projection = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER }; Cursor names = getContentResolver().query(uri, projection, null, null, null); int indexName = names.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME); int indexNumber = names.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); names.moveToFirst(); do { String name = names.getString(indexName); Log.e("Name new:", name); String number = names.getString(indexNumber); Log.e("Number new:","::"+number); } while (names.moveToNext()); } </code></pre> <p>The above retrun all the name and number from from your contact database..</p> <p>if you even need email id you add these lines also:::</p> <pre><code>while (cur.moveToNext()) { String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); Cursor email = cr.query( ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", new String[]{id}, null); while (email.moveToNext()) { //to get the contact names // if the email addresses were stored in an array String emailid = email.getString(email.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)); Log.e("Email id ::", emailid); String emailType = email.getString(email.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)); Log.e("Email Type ::", emailType); } email.close(); } </code></pre>
 

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