How to get bitmap from a url in android?

SyntaxFix
May 6, 2022

I have a uri like which has an image

file:///mnt/...............

How to use this uri to get the image but it returns null, please tell me where i am wrong.

Bitmap bitmap = BitmapFactory.decodeFile(uri.getPath());

Simple way to do

This is a simple one line way to do it:

try {
URL url = new URL("http://....");
Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch(IOException e) {
System.out.println(e);
}

--

--

SyntaxFix

Curated Solutions On Popular Questions — On All Programming Languages, Cloud Computing, Tools etc