Creating an app in which I am fetching all device contact in recyclerview using the content provider. My all contact and contact name is coming but contact image is not showing.
My Image is null but the image is set on my device contact. Here what I have done.
private void getAllContacts() {
ContentResolver contentResolver = getActivity().getContentResolver();
Cursor cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
if (cursor.getCount() > 0) {
while (cursor.moveToNext()) {
int hasPhoneNumber = Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)));
if (hasPhoneNumber > 0) {
String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String image_uri = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_URI));
contactVO = new Contact();
contactVO.setContactImage(image_uri);
contactVO.setContactName(name);
/*if (image_uri != null) {
image.setImageURI(Uri.parse(image_uri));
}*/
phoneCursor = contentResolver.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{id},
null);
if (phoneCursor.moveToNext()) {
phoneNumber = phoneCursor.getString(phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
contactVO.setContactNumber(phoneNumber);
if (Objects.equals(phoneNumber, mobile)) {
contactArrayList.add(contact);
}
}
phoneCursor.close();
//object of model class
contactArrayList.add(contactVO);
}
}