Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Find image for contact list in Android Java
How to get image of contact list? I was using cursor to get contact list. Here how it looks like.
ArrayList<HashMap<String, String>> contactList = new ArrayList<>();
HashMap<String, String> data;
String name,phoneNumber;
Cursor c = activity.getContentResolver().query(Phone.CONTENT_URI,null,null,null,ContactsContract.Contacts.DISPLAY_NAME+" ASC ");
while(c.moveToNext()){
name = c.getString(c.getColumnIndex(Phone.DISPLAY_NAME));
phoneNumber = c.getString(c.getColumnIndex(Phone.NUMBER));
data = new HashMap<>();
data.put(Constants.NAME, name);
data.put(Constants.PHONE_NUMBER,phoneNumber);
contactList.add(data);
}
c.close();
If you look at contact list then there will be some image. You can set a custom image if you want. Now, I want to get that image for my application? How to get that?
Research :
-
I had searched for Image or Photo variable in ContactsContract.class. I had executed suspicious variable either but they weren't returning any URI or bitmap.
-
I had searched in Internet also (I didn't any accurate result).
1 answer
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
Anonymous | (no comment) | Oct 8, 2021 at 04:29 |
See https://developer.android.com/reference/android/provider/ContactsContract.Contacts.Photo
There's PHOTO_URI in ContactsContract.class. Fetch it following way.
String photo = c.getString(c.getColumnIndex(Phone.PHOTO_URI));
It's URI not URL. Don't confuse with URL.
Now, you got URI. Then you have to find Bitmap for that picture.
bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), Uri.parse(photo));
Now you can show the picture using setImageBitmap
imgPic.setImageBitmap(bitmap);
0 comment threads