Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is a an HTTP client library that might be supported in Android now, but for any fine grain control you can use URL &amp; HttpURLConnection. the code will look something like this:</p> <pre><code>URL connectURL = new URL(&lt;your URL goes here&gt;); HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection(); // do some setup conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); conn.setRequestMethod("GET"); // connect and flush the request out conn.connect(); conn.getOutputStream().flush(); // now fetch the results String response = getResponse(conn); </code></pre> <p>where getResponse() looks something like this, in your case you are getting a pile of binary data back you might want to change the StringBuffer to a byte array and chunk the reads by a larger increment.</p> <pre><code>private String getResponseOrig(HttpURLConnection conn) { InputStream is = null; try { is = conn.getInputStream(); // scoop up the reply from the server int ch; StringBuffer sb = new StringBuffer(); while( ( ch = is.read() ) != -1 ) { sb.append( (char)ch ); } return sb.toString(); } catch(Exception e) { Log.e(TAG, "biffed it getting HTTPResponse"); } finally { try { if (is != null) is.close(); } catch (Exception e) {} } return ""; } </code></pre> <p>As you are talking about image data which can be large, other things you need to be assiduous about in Android is making sure you release your memory as soon as you can, you've only got 16mb of heap to play with for all apps and it runs out fast and the GC will drive you nuts if you aren't really good about giving back memory resources</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload