Question

Hello I am trying to get Bitmap from URL, Here this URL is redirecting to the another https URL.

URL : http://graph.facebook.com/244054592454345/picture

I am trying to get bitmap like below but this is not working for me, tried this Android : Getting a Bitmap from a url connection (graph.facebook.com) that redirects to another url but not worked for me.

Using below code, I am always getting null in the bitmap.

URL imgUrl = new URL("http://graph.facebook.com/{user-id}/picture?type=large");
InputStream in = (InputStream) imgUrl.getContent();
Bitmap  bitmap = BitmapFactory.decodeStream(in);

Any idea to get bitmap from a link which redirect to another as like me ?

Was it helpful?

Solution

This below code solved my problem and working fine.

URL fbAvatarUrl = new URL("http://graph.facebook.com/"+userProfileModel.getFacebookID()+"/picture");
HttpGet httpRequest = new HttpGet(fbAvatarUrl.toString()); 
DefaultHttpClient httpclient = HttpClient.getInstance(); 
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity(); 
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); 
Bitmap  fbAvatarBitmap = BitmapFactory.decodeStream(bufHttpEntity.getContent());
httpRequest.abort();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top