处理Android上的网络中断

时间:2012-01-17 20:52:31

标签: android

目前,当我的应用程序使用HTTPURLConnection从互联网上获取大文件并且设备丢弃了3G / 4G / Wifi服务时,它所获取的数据无法完成或恢复。如何让它恢复并完成?

我目前的代码:

// set the URL that points to a file to be downloaded
URL url = new URL(downloadURL);

// create the new connection
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

// set up some things on the connection
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);

// connect and download
urlConnection.connect();

// used in reading the data from the internet
InputStream inputStream = urlConnection.getInputStream();
urlConnection.disconnect();

0 个答案:

没有答案