In Android, what is the simplest approach to the following:
Remote images are part of an email that is not included in the message itself but is downloaded from the internet when you view the email.
Remote content are parts of a message (such as images, stylesheets, or videos) which are not included in the message itself, but are downloaded from the Internet when you view the message. Remote content is a privacy concern because it allows the message sender to know: each time you view the message.
Message: "Unable to load remote content privately" appears at the top of an email on your iOS device. This message appears in iOS 15.0 or later versions if Apple's Mail Privacy Protection feature is enabled on your device. In some cases, this message may also appear if you are using a VPN for your device.
Here's a method that I actually used in an application and I know it works:
try {
URL thumb_u = new URL("http://www.example.com/image.jpg");
Drawable thumb_d = Drawable.createFromStream(thumb_u.openStream(), "src");
myImageView.setImageDrawable(thumb_d);
}
catch (Exception e) {
// handle it
}
I have no idea what the second parameter to Drawable.createFromStream
is, but passing "src"
seems to work. If anyone knows, please shed some light, as the docs don't really say anything about it.
The easiest way so far is build a simple image retriver:
public Bitmap getRemoteImage(final URL aURL) {
try {
final URLConnection conn = aURL.openConnection();
conn.connect();
final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
final Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
return bm;
} catch (IOException e) {}
return null;
}
Then, you just have to supply a URL to the method and it will returns a Bitmap
. Then, you will just have to use the setImageBitmap
method from ImageView
to show the image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With