0

I take photoUri contact by code

  Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
  String photoUri = people.getString(people.getColumnIndex(ContactsContract.Contacts.PHOTO_URI));

and put it into Image by code

 Uri uri = Uri.parse(photoUri);
 img.setImageURI(uri);

but don't have any image display.

Could any body solve my problem.

Hoang
  • 829
  • 11
  • 18
  • Did you try to print out the content of `photoUri` ? It should be something valid – Nguyen Quang Anh Feb 11 '16 at 17:04
  • Most [image loading libraries](http://android-arsenal.com/tag/46) can handle that for you, also handling doing the work on a background thread, so as not to freeze your UI. I recommend Picasso, personally. – CommonsWare Feb 11 '16 at 17:06
  • @NguyenQuangAnh result was System.out is "content://com.android.contacts/display_photo/1" – Hoang Feb 11 '16 at 17:13

1 Answers1

0

1- Try by creating bitmap from your "photoUri", Add a new function :-

public static Bitmap getBitmapFromURL(String src) {
try {
    URL url = new URL(src);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoInput(true);
    connection.connect();
    InputStream input = connection.getInputStream();
    Bitmap myBitmap = BitmapFactory.decodeStream(input);
    return myBitmap;
} catch (IOException e) {
    e.printStackTrace();
    return null;
}}

2- Now set this bitmap to your image view:-

 if(photoUri!=null)
   img.setImageBitmap(getBitmapFromURL(photoUri));
Adarsh Yadav
  • 3,752
  • 3
  • 24
  • 46
  • It seem not true because of function setImageURI() is link URI but function Bitmap isn't it. And I paste your code into my app, it also have problem in function setImageURI(). – Hoang Feb 11 '16 at 17:20
  • @Hoang :- Yes you are right it should be "setImageBitmap()",I have updated my answer please check now !! – Adarsh Yadav Feb 11 '16 at 17:23
  • @Hoang :- Also check this answer http://stackoverflow.com/a/23172208/1384010 Hope this will help you !!! – Adarsh Yadav Feb 11 '16 at 17:28