android 文件断点下载库使用

类库地址:https://github.com/sungerk/android-downloader


1.首先加入连接网络权限

   <uses-permission android:name="android.permission.INTERNET"></uses-permission>

 2.文件读写操作权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>

 3.使用方法如下:


 <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();


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。