标签:
类库地址:https://github.com/sungerk/android-downloader
1.首先加入连接网络权限
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
<span style="white-space:pre"> </span>String urlString = "url"; <span style="white-space:pre"> </span>String localPath = Environment.getExternalStorageDirectory() .getAbsolutePath() + "/local"; <span style="white-space:pre"> </span>downloader = new Downloader(this, urlString, localPath, "weibo_1790.apk", new OnDownloadListener() { @Override public void onFinish(String msg) { } @Override public void onError(String msg) { } @Override public void onProgress(int percent, int total, int completeSize) { mProgressBar.setProgress(percent); tv_total.setText(completeSize + "/" + total); } @Override public void onSpeed(String speed) { super.onSpeed(speed); tv_speed.setText("下载速度" + speed); } }); //开始下载 #downloader.start(); //暂停下载 #downloader.pause(); //删除下载 #downloader.delete(); //重新下载 #downloader.reset();
标签:
原文地址:http://blog.csdn.net/s228245214/article/details/44927155