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
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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

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

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

0 comment threads

Sign up to answer this question »