0

I am getting profile image from Facebook SDK, it returns me a url. When I open it in browser it shows the image. But when I convert it into bitmap, it returns null. Here is my code:

String id = user.getId();
try {
      URL image_path = new URL("http://graph.facebook.com/"+ id+ "/picture?type=large");
      Bitmap profPict = BitmapFactory.decodeStream(image_path.openConnection().getInputStream());
      System.out.println("profPict::> " + profPict);
      ImageView img= (ImageView)findViewById(R.id.textView2);
      img.setImageBitmap(profPict);
      System.out.println("image::> " + image_path);
}
catch (Exception e) {
      e.printStackTrace();
} 
Adam Azad
  • 11,171
  • 5
  • 29
  • 70
  • Use this link [1]: http://stackoverflow.com/questions/19175133/how-to-set-a-image-to-a-image-view-from-a-url-android – Minp Mar 25 '15 at 06:07

2 Answers2

0
 public  Bitmap getBitmapFromURL(String srcurl){
        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;
        }
    }
swetha
  • 45
  • 2
  • 13
0

Use any of the third party libraries available which will accept URL and the ImageView and will download and set the image in the ImageView.

Android Universal Image Loader is quite useful.

Jayakrishnan Salim
  • 977
  • 1
  • 10
  • 24