Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs

Dashboard
Notifications
Mark all as read
Q&A

Find image for contact list in Android Java

+1
−0

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).

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

1 answer

+1
−0

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);
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »