Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You better return the bitmap from <code>doInBackground</code> and take it from parameter in <code>onPostExecute()</code></p> <pre><code>class DownloadImageTask extends AsyncTask&lt;String, Integer, Bitmap&gt; { @Override protected Bitmap doInBackground(String... url) { Bitmap bitmap = DownloadImage(url[0]); return bitmap ; } @Override protected void onProgressUpdate(Integer... args) { mProgressDialog.setProgress(args[0]); } @Override protected void onPostExecute(Bitmap bmp) { ImageView img = (ImageView) findViewById(R.id.img); img.setImageBitmap(bmp); img.setVisibility(View.INVISIBLE); imgInfo = "Height: " + bitmap.getWidth() + " px" + "\n" + "Width: " + bitmap.getHeight() + " px" + "\n" + "File Size: " + fileSize / 1024 + " KB" + "\n" + "Image Name: " + getString(R.string.img_name); isDownloaded = true; mProgressDialog.dismiss(); } </code></pre> <p>**</p> <h2>EDIT :</h2> <p>** <br> Once inputstream reaches its end, you cannot read anymore data from it. You should write the <code>InputStream</code> to a <code>byte array</code> instead and then convert the bytearray to a bitmap.</p> <pre><code>private Bitmap OpenHttpConnection(String urlString) throws IOException { ........ ........ byte data[] = new byte[1024]; long total = 0; int count = 0; ByteArrayOutputStream bos = new ByteArrayOutputStream(); while ((count = in.read(data)) != -1) { total += count; bos.write(data, 0, count); publishProgress((int)(total*100/fileSize)); } return BitmapFactory.decodeByteArray(bos.toByteArray(),0,bos.size()); } </code></pre>
 

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