android - How to handle switch from 3G to WIFI? UrlConnection TimeOut does not throw Exception -


my application needs download big files. use service download show progress in notification. problem during download time user can switch 3g wifi. in case progress stops no exception thrown. how handle situation properly?

url url = new url(myurl); urlconnection conexion = url.openconnection(); conexion.setreadtimeout(10000); conexion.setconnecttimeout(10000); conexion.connect(); int lenghtoffile = conexion.getcontentlength(); // downlod file inputstream input = new bufferedinputstream(url.openstream()); outputstream output = new fileoutputstream(targetfilepath);  byte data[] = new byte[1024];  long total = 0; while ((count = input.read(data)) != -1) {     total += count;     // publishing progress....     updateprogress(downloadnm, downloadnotification, (int)total*100/lenghtoffile);     output.write(data, 0, count); } output.flush(); output.close(); input.close(); 

take @ httpclient-library. provides more options url class, , might problem.

http://developer.android.com/reference/org/apache/http/client/httpclient.html


Comments

Popular posts from this blog

SAP Web Service from .NET via WCF -

Optimized Line drawing in QT -

datetime - str to time in python -