flash76
flash76

Reputation: 382

How do I get an image from a remote source (url) and show it in ImageView?

I am building an Android Things "kiosk" style application and I want an image to show in the background like a wallpaper. I'm using Unsplash Source to get a random image but the source URL (https://source.unsplash.com/1080x1920/?long-exposure) always redirects to an image URL, so I can't use this:

InputStream is = (InputStream) new URL("https://source.unsplash.com/1080x1920/?long-exposure").getContent();
Drawable d = Drawable.createFromStream(is, "");
niceWallpaper.setImageDrawable(d);

Is there a way to do this?

Upvotes: 0

Views: 193

Answers (2)

Heaven
Heaven

Reputation: 536

Using Picasso can solve your problem.

String yourUrl = "https://source.unsplash.com/1080x1920/?long-exposure";
Picasso.with(MyApplication.getAppContext()).load(yourUrl).placeholder(defaultImage).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).into(YourImageView);

Upvotes: 2

farhanjk
farhanjk

Reputation: 1762

Use Picasso.

Picasso.get().load("https://source.unsplash.com/1080x1920/?long-exposure")
                            .into(imageView);

Upvotes: 1

Related Questions