Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to download image if URL dont have www in android
    text
    copied!<p>I am trying to download an image from a URL. The problem I am facing is if the URL dont have www then I get error but if I add www it works fine. I am getting these URL from a webservice there are chances that some have www and some dont have and I am looking a solution to get rid of this issue.</p> <p>If the URL is like that then no problem: <a href="http://www.grindzmyreels.com/wp-content/uploads/2013/02/minion.jpg" rel="nofollow">http://www.grindzmyreels.com/wp-content/uploads/2013/02/minion.jpg</a></p> <p>But in this case I get error: <a href="http://grindzmyreels.com/wp-content/uploads/2013/02/minion.jpg" rel="nofollow">http://grindzmyreels.com/wp-content/uploads/2013/02/minion.jpg</a></p> <p>Here is the code:</p> <pre><code>public void DownloadImage() { HttpClient client = new DefaultHttpClient(); HttpResponse httpResponse; Bitmap bmp = null; try{ httpResponse = client.execute(new HttpGet("http://www.grindzmyreels.com/wp-content/uploads/2013/02/minion.jpg")); //int responseCode = httpResponse.getStatusLine().getStatusCode(); HttpEntity entity = httpResponse.getEntity(); if (entity != null) { InputStream in = entity.getContent(); bmp = BitmapFactory.decodeStream(in); in.close(); String Path = bmp.toString(); Context context = getApplicationContext(); File mydir = context.getDir("MyFolder", Context.MODE_PRIVATE); //Creating an internal dir; File fileWithinMyDir = new File(mydir, Path ); //Getting a file within the dir. FileOutputStream out = new FileOutputStream(fileWithinMyDir); out.close(); extStorageDirectory = Environment.getExternalStorageDirectory().toString(); OutputStream outStream = null; File file = new File(extStorageDirectory, Name+".PNG"); outStream = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream); filePath = file.toString(); outStream.flush(); outStream.close(); } } catch (ClientProtocolException e) { client.getConnectionManager().shutdown(); e.printStackTrace(); } catch (IOException e) { client.getConnectionManager().shutdown(); e.printStackTrace(); } } </code></pre> <p>Thanks alot.</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