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());
} 开发者_StackOverflowcatch (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
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.
精彩评论