Declare a global variable
// Hash Maps Map<String, String> nameEmailMap = new HashMap<String, String>();
Then use the function below
private void getEmailIDs() { Cursor emails = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null, null, null); // Loop Through All The Emails while (emails.moveToNext()) { String name = emails.getString(emails.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); String email = emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS)); // Enter Into Hash Map nameEmailMap.put(email, name); } // Get The Contents of Hash Map in Log for (Map.Entry<String, String> entry : nameEmailMap.entrySet()) { String key = entry.getKey(); Log.d(TAG, "Email :" + key); String value = entry.getValue(); Log.d(TAG, "Name :" + value); } emails.close(); }
Remember that in the example above, the key is the email address and the value is the name, so read the contents, for example, mahaXXXX @gmail. com-> Mahatma Gandhi instead of Mahatma Gandhi--> mahaXXXX@gmail.com
DragonFire Jan 17 '19 at 0:13 2019-01-17 00:13
source share