How can I get all the names of the contacts in my Android and put them into array of strings?
Open your Contacts app and tap the Options button (three dots), and select Contacts Manager. On the next screen, tap on Contacts to display from the menu.
Step 1: First, you need to open the menu and then click “Import/Export” button. Step 2: Then click the “Export to SIM card” option. And select all the contacts. Step 3: Now all contacts will get transferred to the SIM.
Go to Setting on your Android or Samsung. Click Account and Google account. Tap on Account sync and check if your contacts button is toggled on. If yes, you can also turn it off then on.
Try this too,
private void getContactList() { ContentResolver cr = getContentResolver(); Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); if ((cur != null ? cur.getCount() : 0) > 0) { while (cur != null && cur.moveToNext()) { String id = cur.getString( cur.getColumnIndex(ContactsContract.Contacts._ID)); String name = cur.getString(cur.getColumnIndex( ContactsContract.Contacts.DISPLAY_NAME)); if (cur.getInt(cur.getColumnIndex( ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) { Cursor pCur = cr.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{id}, null); while (pCur.moveToNext()) { String phoneNo = pCur.getString(pCur.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER)); Log.i(TAG, "Name: " + name); Log.i(TAG, "Phone Number: " + phoneNo); } pCur.close(); } } } if(cur!=null){ cur.close(); } }
If you need more reference means refer this link Read ContactList
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With