Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Download of bitmap returns null sometimes
    primarykey
    data
    text
    <p>I am using the code below in asyn task to download a bitmap to be added to my custom class. however sometimes it return nulls with no IOException or any exception. i am not very sure what can be done</p> <pre><code> public Bitmap downloadFile(String fileUrl){ URL myFileUrl =null; try { myFileUrl= new URL(fileUrl); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection(); conn.setDoInput(true); //conn.setReadTimeout(500000000); conn.connect(); InputStream is = conn.getInputStream(); BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(is, null, o); is.close(); conn.disconnect(); int scale = 1; int IMAGE_MAX_SIZE=400; if (o.outHeight &gt; IMAGE_MAX_SIZE || o.outWidth &gt; IMAGE_MAX_SIZE) { scale = (int)Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5))); } //Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; conn= (HttpURLConnection)myFileUrl.openConnection(); conn.setDoInput(true); //conn.setReadTimeout(500000000); conn.connect(); is = conn.getInputStream(); Bitmap b = BitmapFactory.decodeStream(is, null, o2); if (b==null) Log.e(Config.log_id, " Download image failed"); return b; } catch (IOException e) { Log.e(Config.log_id, " Download image failed"+e.getMessage()); e.printStackTrace(); } return null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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