Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android get Image source from an https url?

Tags:

android

i am trying to get an image from a https url but it doesnt seem to display and get the image correctly but works fine on my computer browser.

i have tested out a http url pointing to a different image and it works fine.

my code is below:

public Bitmap getContactPhoto(String url) {
        Bitmap pic = null;
        try {
            pic = BitmapFactory
                    .decodeStream((InputStream) new URL(
                            "https://mail.google.com/mail/photos/static/AD34hIjbK2m-Lj333E4nBcCkBC3MYl2tTs0xizuSqUOP3-Jd6DOrpFg1M5HG8jXh0MuPbeFepInZZDu92Dx8ST4b59EbOKmfYTortuuO3P1_Ohyu7b7a3gc")
                            .getContent());
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return pic;

    }

here is the code from the activity class that calls the method above:

private ImageView mContactPhoto;
private ContactDetailsViewHelper mViewHelper;

mContactPhoto = (ImageView) findViewById(R.id.contact_photo);
mViewHelper = new ContactDetailsViewHelper(mContext);
mContactPhoto.setImageBitmap(mViewHelper.getContactPhoto(mDetail.getImageRef()));

ignore the mDetail.getImageRef, that passes the real url value but for this case i tried hard coding the url as you can see from the getContactPhoto method.

thanks

like image 318
Jonathan Avatar asked Nov 19 '25 06:11

Jonathan


1 Answers

You are only able to see it in the browser because you're logged into GMail and have the appropriate cookies to prove it. Try viewing the image after logging out or by opening Incongnito/Private Browsing/InPrivate window. You'd need to find another source of this image.

like image 85
kichik Avatar answered Nov 21 '25 20:11

kichik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!