Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is what I implemented:</p> <pre><code>private String[] getContactList(){ ContentResolver cr = getContentResolver(); Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); Log.i(LOG_TAG, "get Contact List: Fetching complete contact list"); ArrayList&lt;String&gt; contact_names = new ArrayList&lt;String&gt;(); if (cur.getCount() &gt; 0) { while (cur.moveToNext()) { String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); if (cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER.trim())).equalsIgnoreCase("1")) { if (name!=null){ //contact_names[i]=name; Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",new String[]{id}, null); while (pCur.moveToNext()) { String PhoneNumber = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); PhoneNumber = PhoneNumber.replaceAll("-", ""); if (PhoneNumber.trim().length() &gt;= 10) { PhoneNumber = PhoneNumber.substring(PhoneNumber.length() - 10); } contact_names.add(name + ":" + PhoneNumber); //i++; break; } pCur.close(); pCur.deactivate(); // i++; } } } cur.close(); cur.deactivate(); } String[] contactList = new String[contact_names.size()]; for(int j = 0; j &lt; contact_names.size(); j++){ contactList[j] = contact_names.get(j); } return contactList; } </code></pre> <p>You can call this function and maybe use an AutoCompleteTextView to display and pick contact name and 10 digit number. This function returns String array you can directly return the arrayList and remove the last for loop.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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