Giter VIP home page Giter VIP logo

downloadmanager's Introduction

DownloadManager 文件下载器

多线程下载,支持断点续传,分为Android和Java两个版本。

效果图

用法

RequestCall call = new GetBuilder()
        .name(name)
        .folder(folder)
        .uri(url)
        .tag(tag)
        .build();
DownloadManager.getInstance(this).start(call, new FileCallBack() {
    @Override
    public void onStart(String tag) {
        L.d("=====> onStart " + tag);
    }

    @Override
    public void onDownloadProgress(String tag,long finished, long totalLength, int percent) {
        L.d("=====> onDownloadProgress: " + percent);
    }

    @Override
    public void onDownloadPaused() {
        L.d("=====> onDownloadPaused: " );
    }

    @Override
    public void onDownloadCanceled() {
        L.d("=====> onDownloadCanceled: " );
    }

    @Override
    public void onDownloadFailed(DownloadException e) {
        L.d("=====> onDownloadFailed: " + e.getErrorMessage());
    }

    @Override
    public void onDownloadCompleted(File file) {
        L.d("=====> onDownloadCompleted: " + file.getAbsolutePath());
    }
});
        

简单调用

如果只想获取下载进度和结果,还可以这样调用。

new GetBuilder()
	.name("JOKER_山本彩.mp4")
	.folder(new File("F:/"))
	.uri(url)
	.tag(tag)
	.build()
	.execute(new FileCallBack() {
		@Override
		public void onStart(String tag) {
			// UI Thread
		}

	    @Override
		public void onDownloadProgress(String tag, long finished, long totalLength, int percent) {
			// UI Thread
		}

		@Override
		public void onDownloadFailed(DownloadException e) {
			// UI Thread
		}

		@Override
		public void onDownloadCompleted(File file) {
			// UI Thread
		}
	});

其他API

  1. 取消一个下载任务
DownloadManager.getInstance(this).cancel(tag);`
  1. 暂停一个下载任务
DownloadManager.getInstance(this).pause(tag);
  1. 取消所有下载任务
DownloadManager.getInstance(this).pauseAll();
  1. 暂停所有下载任务
DownloadManager.getInstance(this).cancelAll();

依赖

Android: 拷贝libs目录downloader-android-1.0.jar到项目引用即可。

Java: 拷贝libs目录downloader-java-1.0.jar到项目中,该jar需要额外引入sqlite-jdbc.jar,本项目使用的版本是sqlite-jdbc-3.8.11.1.jar

License

Copyright 2017 wangli

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

downloadmanager's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

downloadmanager's Issues

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.