Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8758091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:27:31+00:00 2026-06-13T14:27:31+00:00

I let the user select a contact in my app, and I display it

  • 0

I let the user select a contact in my app, and I display it on the home screen widget, but the photo is not displayed and I don’t know what’s wrong.

This is how I get the reference to the photo:

...
Cursor c = null;
try {
    c = getContentResolver().query(uri, new String[] {
            ContactsContract.CommonDataKinds.Phone.NUMBER,
            ContactsContract.CommonDataKinds.Phone.TYPE,
            ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
            ContactsContract.CommonDataKinds.Phone.PHOTO_ID },
            null, null, null);

    if (c != null && c.moveToFirst()) {
        String number = c.getString(0);
        int type = c.getInt(1);
        String name = c.getString(2);
        int photo = c.getInt(3);
        showSelectedNumber(type, number, name, photo);
    }
}

This is how I display it:

public void showSelectedNumber(int type, String number, String name, int photo) {
    mAppWidgetPrefix.setText(name);
    pickedNumber.setText(number);
    pickedPhoto.setImageResource(photo);
}

Why doesn’t it work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:27:32+00:00Added an answer on June 13, 2026 at 2:27 pm

    You are trying to set ID of the row from ContactsContract.Data table as a resource ID into your ImageView. And surely it wouldn’t work. It doesn’t even make any sense.

    You should retrieve the original photo from database first and only then you can show it.

    For example, you can use this code to retrieve image bitmap with the help of row ID pointing to the image data (i’ve recreated some pieces of code just to test it):

    private void queryContactInfo(int rawContactId) {
        Cursor c = getContentResolver().query(
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                new String[] {
                        ContactsContract.CommonDataKinds.Phone.NUMBER,
                        ContactsContract.CommonDataKinds.Phone.TYPE,
                        ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                        ContactsContract.CommonDataKinds.Phone.PHOTO_ID
                }, ContactsContract.Data.RAW_CONTACT_ID + "=?", new String[] { Integer.toString(rawContactId) }, null);
        if (c != null) {
            if (c.moveToFirst()) {
                String number = c.getString(0);
                int type = c.getInt(1);
                String name = c.getString(2);
                int photoId = c.getInt(3);
                Bitmap bitmap = queryContactImage(photoId);
                showSelectedNumber(type, number, name, bitmap);
            }
            c.close();
        }
    }
    
    private Bitmap queryContactImage(int imageDataRow) {
        Cursor c = getContentResolver().query(ContactsContract.Data.CONTENT_URI, new String[] {
            ContactsContract.CommonDataKinds.Photo.PHOTO
        }, ContactsContract.Data._ID + "=?", new String[] {
            Integer.toString(imageDataRow)
        }, null);
        byte[] imageBytes = null;
        if (c != null) {
            if (c.moveToFirst()) {
                imageBytes = c.getBlob(0);
            }
            c.close();
        }
    
        if (imageBytes != null) {
            return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); 
        } else {
            return null;
        }
    }
    
    public void showSelectedNumber(int type, String number, String name, Bitmap bitmap) {
        mInfoView.setText(type + " " + number + " " + name);
        mImageView.setImageBitmap(bitmap); // null-safe
    }
    

    You can also see http://developer.android.com/reference/android/provider/ContactsContract.Contacts.Photo.html
    as a convenient provider directory for getting contacts’ photos. There is an example as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know how to let user select an image from UIImagePickerController, but I don't
I am using SuggestBox to let user to select values. But however when there
I let the user select a photo from the iPhone library, and I grab
In my app i need to use something that will let the user select
I am using jQuery and the widget Selectable to let my user select files
In my app I'm using a spinners to let the user select an item
I am developing a chatting/messaging app and I want to let the user select
In my app i let the user select one image from the media gallery.
I need to let the user select a photo from the Photo Library and
I use GetOpenFilename() to let the user select a file. Here is the code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.