Reputation: 1
i have this url http://app.oviewz.com/proceso_seleccions/110.png?style=medium&token=q9W0BQpU. when u put on any web browser automatically download the file but when i try to download by using this android code:
String urllogo="http://app.oviewz.com/proceso_seleccions/110.png?style=medium&token=q9W0BQpU";
URL url = new URL(urllogo);
HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
// <span id="IL_AD2" class="IL_AD">connect</span>
urlConnection.connect();
// set the path where we want to save the file
File SDCardRoot = Environment.getExternalStorageDirectory();
// create a new file, to save the <span id="IL_AD7"
// class="IL_AD">downloaded</span> file
File file = new File(SDCardRoot, "logo.jpg");
FileOutputStream fileOutput = new FileOutputStream(file);
// Stream used for reading the data from the internet
InputStream inputStream = urlConnection.getInputStream();
// this is the total size of the file which we are <span
// id="IL_AD12" class="IL_AD">downloading</span>
// create a buffer...
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ((bufferLength = inputStream.read(buffer)) > 0) {
fileOutput.write(buffer, 0, bufferLength);
}
// close the output stream when complete //
fileOutput.close();
is raised FileNotFoundException. anyone can help me what i'm doing wrong?
Upvotes: 0
Views: 350
Reputation: 1726
When I open this URL in my browser, it redirects me to http://app.oviewz.com/. This means that the image is not available publicly i.e. You need to be logged in to view the image. So, you can't directly download the image using URL. If the website has some API for login, you can use that to get required access token and send the same in header of this request, the way they do in facebook or g+ API.
Upvotes: 1