title: Retrieving Bitmap from Redirected URL
body: <p>I am using the following void method to get a Bitmap image from a URL:</p>
  
  <pre><code>public static Bitmap downloadBitmap(String url) {
          final AndroidHttpClient client = AndroidHttpClient.newInstance("Android");
          final HttpGet getRequest = new HttpGet(url);
  
          try {
              HttpResponse response = client.execute(getRequest);
              final int statusCode = response.getStatusLine().getStatusCode();
              if (statusCode != HttpStatus.SC_OK) { 
                  Log.w("ImageDownloader", "Error " + statusCode + " while retrieving bitmap from " + url); 
                  return null;
              }
  
              final HttpEntity entity = response.getEntity();
              if (entity != null) {
                  InputStream inputStream = null;
                  try {
                      inputStream = entity.getContent(); 
                      final Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
                      return bitmap;
                  } finally {
                      if (inputStream != null) {
                          inputStream.close();  
                      }
                      entity.consumeContent();
                  }
              }
          } catch (Exception e) {
              // Could provide a more explicit error message for IOException or IllegalStateException
              getRequest.abort();
              Log.e("ImageDownloader", "Error while retrieving bitmap from " + url);
          } finally {
              if (client != null) {
                  client.close();
              }
          }
          return null;
      }
  </code></pre>
  
  <p>The most common URL I feed with this method is this: <a href="http://graph.facebook.com/+FACEBOOK_USER_ID+/picture" rel="nofollow">http://graph.facebook.com/+FACEBOOK_USER_ID+/picture</a>, but this URL redirects to <a href="http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/y9/r/xxxxx.gif" rel="nofollow">http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/y9/r/xxxxx.gif</a>. That’s why I’m not getting the Bitmap image, what I’m getting is an error related to a 302 Redirect. 
  How do I handle redirected URLs, and get the Bitmap file?</p>