I would like to download an image from an url, using this example:
public Bitmap getBitmapFromURL(String src) {
try {
java.net.URL url = new java.net.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;
}
}
Unfortunately the returned myBitmap
is null
, and I have no idea why. The url is a local ip: http://192.168.0.101:7777/my_image.png
- I get no error messages
- If I open this link in the browser, it displays it.
android:usesCleartextTraffic="true"
is enabled, and my json requests work withVolley
.- I tried to use
BufferedInputStream
, but that also does not work