What I an trying to achieve:
I am downloading a file and showing updates in the Expanded Notification bar's Views. For android
The problem
How to handle the situation when server gets disconnected while downlading?
What I have done so far:
When Input stream is read and net gets disconnected, It should throw an exception. But it isnt throwing an exception.
This code here is s simple download loop:
try{
while ( (bufferLength = inputStream.read(buffer)) > 0 )
{
fileOutput.write(buffer, 0, bufferLength);
//add up the size so we know how much is downloaded
downloadedSize += bufferLength;
percent=(int)(100 *( (float)downloadedSize/totalSize ));
Log.i("Downloaded", String.valueOf(downloadedSize) );
}
}
ucon.disconnect();
return 1;
}
catch (IOException e) {
Log.d("Download", "Error: " + e);
return 2;
}
I am stunned, why isnt it throwing an exception. What is a work around?