可以做到的。你到底在找什么?下载程序或如何进行检查?
这里是下载方法,您应该在AsyncTask中运行它。
/**
* Downloads a remote file and stores it locally
* @param from Remote URL of the file to download
* @param to Local path where to store the file
* @throws Exception Read/write exception
*/
static private void downloadFile(String from, String to) throws Exception {
HttpURLConnection conn = (HttpURLConnection)new URL(from).openConnection();
conn.setDoInput(true);
conn.setConnectTimeout(10000); // timeout 10 secs
conn.connect();
InputStream input = conn.getInputStream();
FileOutputStream fOut = new FileOutputStream(to);
int byteCount = 0;
byte[] buffer = new byte[4096];
int bytesRead = -1;
while ((bytesRead = input.read(buffer)) != -1) {
fOut.write(buffer, 0, bytesRead);
byteCount += bytesRead;
}
fOut.flush();
fOut.close();
}
// check for wifi or 3g
ConnectivityManager mgrConn = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
TelephonyManager mgrTel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if ((mgrConn.getActiveNetworkInfo()!=null && mgrConn.getActiveNetworkInfo().getState()==NetworkInfo.State.CONNECTED)
|| mgrTel.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS) {
...
否则,当人们需要通过慢速电话网络下载100m时,他们会发疯。