Giter Site home page Giter Site logo

crazydownload's Introduction

本项目实现了android多线程下载,支持断点下载。

1、添加依赖

1.1、在根目录下的build.gradle中添加以下代码:

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

1.2、然后module中的build.gradle中添加以下代码:

    dependencies {
	        implementation 'com.github.crazyxiaoke:CrazyDownload:1.0.0'
	}

2、初始化

2.1、在Application的onCreate中进行初始化,添加以下代码:

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        DownloadDispatch.getInstance().init(this);
    }
}

2.2、也可以通过DownloadConfig类来设置下载参数。如以下代码:

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        DownloadConfig config = new DownloadConfig.Builder()
                .setMaxDownloadSize(3)  //最大下载数
                .setDownloadThreadSize(3) //每个下载任务开启的最大线程数
                .setDeamon(true)  //是否启动线程保护
                .setDefaultFilePath("/")  //文件保存路径
                .setKeepAliveTime(60)  //线程sleep下存活时间
                .setUnit(TimeUnit.MILLISECONDS) //时间单位
                .build(this);
        DownloadDispatch.getInstance().init(this, config);
    }
}

3、开始使用

    //开始下载
    public void download(String url, DownloadCallback callback) 
    //停止下载
    public void stop(String url);

crazydownload's People

Contributors

crazyxiaoke avatar

Stargazers

UaoanLao avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.