0

I want to display an image in an ImageView which am fetching from a url which I have specified in function. The below is function where am trying to fetch image.

 public Bitmap getBitmapFromUrl(String src){
    try{

        URL url = new URL(src);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream inputStream = connection.getInputStream();
        Bitmap btmp = BitmapFactory.decodeStream(inputStream);

        return btmp;

    }catch (Exception e){

        e.printStackTrace();
        return null;
    }

}

The above function is returning null. The argument src "http://pyplyn.co/magento2pawan/a.jpg".

Please help me. Where I am going wrong....?

Bryan
  • 14,756
  • 10
  • 70
  • 125

1 Answers1

-1

Its better to use libraries like Glide or Picasso rather than this when displaying Image from url

p.mathew13
  • 920
  • 8
  • 16