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 8992547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:58:49+00:00 2026-06-15T22:58:49+00:00

the function i use to get the Uri of the contact image thumbnail from

  • 0

the function i use to get the Uri of the contact image thumbnail from the phone no. :

public static Uri getPhotoURIFromAddress(Context activity, String address) {
    String contactId = getContactIdFromAddress(activity, address);

    ContentResolver contentResolver = activity.getContentResolver();
    try {
        Cursor cursor = contentResolver
                .query(ContactsContract.Data.CONTENT_URI,
                        null,
                        ContactsContract.Data.CONTACT_ID
                                + "="
                                + contactId
                                + " AND "

                                + ContactsContract.Data.MIMETYPE
                                + "='"
                                + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE
                                + "'", null, null);

        if (cursor != null) {
            if (!cursor.moveToFirst()) {
                return null; // no photo
            }
        } else {
            return null; // error in cursor process
        }
        cursor.close();

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    Uri person = ContentUris.withAppendedId(
            ContactsContract.Contacts.CONTENT_URI, Long.valueOf(contactId));
    return Uri.withAppendedPath(person,
            ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
}

Which will return a Uri in the form of :

content://com.android.contacts/contacts/799/photo

now, if i use this Uri in an ImageView with the setImageUri(Uri) function, it works.

But loading a Bitmap is a problem. the function I’m using is :

public static Bitmap getContactBitmapFromURI(Context context, Uri uri) {
        InputStream input = ContactsContract.Contacts
                .openContactPhotoInputStream(context.getContentResolver(), uri);
        if (input == null) {
            return null;
        }
        return BitmapFactory.decodeStream(input);
    }

which always crashes. LogCat is :

12-13 21:40:26.016: E/AndroidRuntime(9076): FATAL EXCEPTION: main
12-13 21:40:26.016: E/AndroidRuntime(9076): java.lang.RuntimeException: Unable to start receiver com.daksh.fss.SMSReceiver: java.lang.IllegalArgumentException: URI: content://com.android.contacts/contacts/799/photo/photo, calling user: com.daksh.fss, calling package:com.daksh.fss
12-13 21:40:26.016: E/AndroidRuntime(9076):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2362)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at android.app.ActivityThread.access$1500(ActivityThread.java:142)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at android.os.Looper.loop(Looper.java:137)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at android.app.ActivityThread.main(ActivityThread.java:4931)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at java.lang.reflect.Method.invokeNative(Native Method)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at java.lang.reflect.Method.invoke(Method.java:511)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at dalvik.system.NativeStart.main(Native Method)
12-13 21:40:26.016: E/AndroidRuntime(9076): Caused by: java.lang.IllegalArgumentException: URI: content://com.android.contacts/contacts/799/photo/photo, calling user: com.daksh.fss, calling package:com.daksh.fss
12-13 21:40:26.016: E/AndroidRuntime(9076):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:170)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at android.content.ContentResolver.query(ContentResolver.java:370)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at android.content.ContentResolver.query(ContentResolver.java:313)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at android.provider.ContactsContract$Contacts.openContactPhotoInputStream(ContactsContract.java:1973)
12-13 21:40:26.016: E/AndroidRuntime(9076):     at android.provider.ContactsContract$Contacts.openContactPhotoInputStream(ContactsContract.java:2004)

please help!

  • 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-15T22:58:50+00:00Added an answer on June 15, 2026 at 10:58 pm

    I dont think you should pass the uri of the photo to openContactphotoinputstream. You just need to pass the uri of the contact itself to get the bitmap.

     Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
      InputStream stream = ContactsContract.Contacts.openContactPhotoInputStream(
                mContext.getContentResolver(), uri);
    

    Or if you are going to pass the contact photo uri then you could use

    public static Bitmap getContactBitmapFromURI(Context context, Uri uri) {
            InputStream input = context.getContentResolver().openInputStream(uri)
            if (input == null) {
                return null;
            }
            return BitmapFactory.decodeStream(input);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the function below to get a DIV to slide-out from
As we know, we could use GetProcAddress to get a function pointer from a
I use redirect() (from uri helper) in every function who need to load the
Which function can I use to get the content of a plain text file?
because when I use the function getUser () do not get the correct id?
I am trying to use the http_get function. But I get a undefined reference
I'm trying to use the jQuery get function to render the results of an
I use the NSHomeDirectory() function to get the app's home folder, and write to
I use the date() function to get day, month and year. $year = date(y);
I am trying to open HTML file from the local URI which I use

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.