android - FileNotFoundException while getting the InputStream during downloading file to SD card using URLConnection -


I am working on an application that has a workflow like this:

1. Pursing Home Page HTTL connections, connect (), do stuff, disconnect (), use data),

2. Then click on the link written on the link, parsing the article or link Download the file based.

The first step works right & amp; The second in the case of paragraph, but when I am trying to download the file from a specific url and save it to an SD card, I got a file not found in this line:

  InputStream InputStream = urlConnection.getInputStream ();   

To do this, my guide (downloading the file) was a code explained here and I allow it in the required manifest for this action, plus any MEDIA_MOUNTED before the download operation & Amp; MEDIA_MOUNTED_READ_ONLY status and it looks like it fits well.

So .. I read a lot about this problem about stack overflow and other places and I tried various suggestions like adding them:

  UrlConnection.setRequestProperty ( "User-agent", "Mozilla / 5.0 (compatible)"); UrlConnection.setRequestProperty ("* / *" "accept",);   

or

  System .setProperty ("http.keepAlive", "false");   

But without success, I am still stucked with fileNotFoundException. I tried to capture the response code from the webpage and it says 404 ..?!

It is strange that if I download a hardcode link to download from any other site, then it downloads the file without any hassle. So to clarify this, I click on the link to the pickup filear variable, but in the next step I just go to fileurl = "somesite / somefile.ext" everything. I can download any file from the web browser which causes problems in my application, so I'm worried about me, where is the problem ..

Any suggestions please ..? 10q

okay .. after no such time .. no answer .. :( Finally I got the solution I have my own, therefore I am posting here because someone expects it to be used.

I have seen a lot in the URL 20 so I mentioned it on URI before using it.

And voila .. Everything was fine .. :) Thanks to everyone for contributing community! ;) Cheers

Comments