当前位置: 首页 > 软件库 > 手机/移动开发 > >

Android-Download-Manager-Pro

授权协议 MIT License
开发语言 Java
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 卢皓轩
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Android-Download-Manager

Android/Java download manager library help you to download files in parallel mechanism in some chunks.

Overview

This library is a download manager android/java library which developers can use in their apps and allow you to download files in parallel mechanism in some chunks and notify developers about tasks status (any download file process is a task). Each download task cross 6 stats in its lifetime.

  1. init
  2. ready
  3. downloading
  4. paused
  5. download finished
  6. end

Usage

In the first stage, you need to include these permissions in your AndroidManifest.xml file

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

After that, import com.golshadi.downloadManager package in your packages folder. So now everything is ready to start.

Let's get started

One of the important benefits of this lib is that you don't need to initialize object completely before getting any reports.

DownloadManagerPro dm = new DownloadManagerPro(Context);

to get report about tasks you can use these methods that will be introduced later on this doc:

public ReportStructure singleDownloadStatus(int token);
public List<ReportStructure> downloadTasksInSameState(int state);
public List<ReportStructure> lastCompletedDownloads();
public boolean unNotifiedChecked();
public boolean delete(int token, boolean deleteTaskFile);

Attention: in this documentation dm stands for DownloadManagerPro object

Initialize DownloadManagerPro

in order to download with this lib you need to set its basic configurations and give him a listener to poke you about tasks status.

void DownloadManagerPro.init(String saveFilePath, int maxChunk, DownloadManagerListener class)
  • String saveFilePath: folder address that you want to save your completed download task in it.
  • int maxChunk : number of maximum chunks. any task is divided into some chunks and download them in parallel. it's better not to define more than 16 chunks; but if you do it's set to 16 automatically.
  • DownloadManagerListener listenerClass in this package an interface created to report developer download tasks status. this interface includes some abstract methods that will be introduced later.

Example:

public class MyActivity extends Activity implements DownloadManagerListener {
    ...
    public void methodName() {
        ...
        // you can only pass this for context but here i want to show clearly
        DownloadManagerPro dm = new DownloadManagerPro(this.getApplicationContext());
        dm.init("downloadManager/", 12, this);
        ...
    }
    ...
}

there are three ways to define your download task, so you can define it any way you want. for example If you didn't set maximum chunks number or sd card folder address it uses your initialized values. these methods return you a task id that you can call to start or pause that task using this token.

int DownloadManagerPro.addTask(String saveName, String url, int chunk, String sdCardFolderAddress, boolean overwrite, boolean priority)

int DownloadManagerPro.addTask(String saveName, String url, String sdCardFolderAddress, boolean overwrite, boolean priority)

int DownloadManagerPro.addTask(String saveName, String url, boolean overwrite, boolean priority)
  • String saveName: defining te name of desired download file.

  • String url : Location of desired downlaod file.

  • int chunk : Number of chunks which download file has been divided into.

  • String sdCardFolder : Location of where user want to save the file.

  • boolean overwrite : Overwrite if exists another file with the same name. If true, overwrite and replace the file. If false, find new name and save it with new name.

  • boolean priority : Grant priority to more desired files to be downloaded.

  • return int task id: task token

Example:

int taskToken = dm.addTask("save_name", "http://www.site.com/video/ss.mp4", false, false);

this method usage is to start a download task. If download task doesn't get started since this task is in downloading state, it throw you an IOException. When download task start to download this lib notify you with OnDownloadStarted interface

void DownloadManagerPro.startDownload(int token) throws IOException
  • int token: It is an assigned token to each new download which is considered as download task id.

Example:

try {
        dm.startDownload(taskToekn);

    } catch (IOException e) {
        e.printStackTrace();
    }

pause a download tasks that you mention and when that task paused this lib notify you with OnDownloadPaused interface

void DownloadManagerPro.pauseDownload(int token)
  • int token: It is an assigned token to each new download which is considered as download task id.

Example:

dm.pauseDownload(taskToekn);

StartQueueDownload method create a queue sort on what you want and start download queue tasks with downloadTaskPerTime number simultaneously. If download tasks are running in queue and you try to start it again it throws a QueueDownloadInProgressException exception.

void DownloadManagerPro.StartQueueDownload(int downloadTaskPerTime, int sortType) throws QueueDownloadInProgressException
  • int downloadTaskPerTime: the number of task that can be downloaded simultaneously

  • int sortType: Grant priority to more desired files to be downloaded.

  • QueueSort.HighPriority : only high priority

  • QueueSort.LowPriority : only low priority

  • QueueSort.HighToLowPriority : sort queue from high to low priority

  • QueueSort.LowToHighPriority : sort queue from low to high priority

  • QueueSort.earlierFirst : sort queue from earlier to oldest tasks

  • QueueSort.oldestFirst : sort queue from old to earlier tasks

Example:

try {
        dm.startQueueDownload(3, QueueSort.oldestFirst);

    } catch (QueueDownloadInProgressException e) {
        e.printStackTrace();
    }

this method pauses queue download and if no queue download was started it throws a QueueDownloadNotStartedException exception.

void DownloadManagerPro.pauseQueueDownload()throws QueueDownloadNotStartedException

Example:

try {
        dm.pauseQueueDownload();

    } catch (QueueDownloadNotStartedException e){
        e.printStackTrace();
    }

Report

In this section we are working with reports since we need to get tasks status and some useful information about those status.


It reports task download information in "ReportStructure" style using a token (download task id) and finally returns the statue of that token.

ReportStruct DownloadManagerPro.SingleDownloadStatus(int token)
  • int token: task token

  • return ReportStructure object and it has a method to convert these info to json

  • int id: task token

  • String name: file name that will be saved on your sdCard

  • int state: download state number

  • String url: file download link

  • long fileSize: downloaded bytes

  • boolean resumable: download link is resumable or not

  • String type: file MIME

  • int chunks: task chunks number

  • double percent: downloaded file percent

  • long downloadLength: size that will get from your sd card after it completely download

  • String saveAddress: save file address

  • boolean priority: true if task was high priority

Example:

ReportStructure report = dm.singleDownloadStatus(taskToken);

It's a report method for returning the list of download task in same state that developers want.

List DownloadManagerPro.downloadTasksInSameState(int state)
  • int state: any download in it's life time across 6 state.
  • TaskState.INIT: task intruduce for library and gave you token back but it didn't started yet.
  • TaskState.READY: download task data fetch from its URL and it's ready to start.
  • TaskState.DOWNLOADING: download task in downloading process.
  • TaskState.PAUSED: download task in puase state. If in middle of downloading process internet disconnected; task goes to puase state and you can start it later
  • TaskState.DOWNLOAD_FINISHED: download task downloaded completely but their chunks did not rebuild.
  • TaskState.END: after rebuild download task chunks, task goes to this state and notified developer with OnDownloadCompleted(long taskToken) interface

Example:

List<ReportStructure> report = dm.downloadTasksInSameState(TaskState.INIT);

This method returns list of last completed Download tasks in "ReportStructure" style, developers can use it for notifying whether the task is completed or not.

List DownloadManagerPro.lastCompletedTasks()
  • return List : list of completed download from last called unNotifiedCheck() method till now.

Example:

List<ReportStructure> completedDownloadTasks = dm.lastCompletedTasks();

This method checks all un notified tasks, so in another "lastCompletedDownloads" call ,completed task does not show up again. “lastCompletedDownloads”: Shows the list of latest completed downloads. Calling this method, all of the tasks that were shown in the previous report, will be eliminated from "lastCompletedDownloads"

void DownloadManagerPro.unNotifiedCheck()

Example:

dm.unNotifiedCheck()

this method delete download task

boolean DownloadManagerPro.delete(int token, boolean deleteTaskFile)
  • int token: download task token
  • boolean deleteTaskFile: deletes download task from database and set deleteTaskFile as true, then it goes to saved folder and delete that file.

*return boolean : if delete is successfully it returns true otherwise false

Example:

dm.delete(12, false);

This method closes database connection.

void DownloadManagerPro.disConnectDB()

Example:

dm.disConnectDb();
  • Android系统下载管理DownloadManager增强方法,可用于包括获取下载相关信息,如: getStatusById(long) 得到下载状态 getDownloadBytes(long) 得到下载进度信息 getBytesAndStatus(long) 得到下载进度信息和状态 getFileName(long) 得到下载文件路径 getUri(long) 得到下载uri getReas

  • 昨天含含糊糊的讲了一下HttpUtils,又有人跟我反馈说,别管看得懂,要照顾到看不懂的,还是要求我写详细一些,我想也是,能看懂的可以不看,重点就是让人好好得到学习的,众口难调嘛,以后我写东西尽量都写的详细一些,适合更多小白用户看,才能更好,更能提高大家的能力。如果你能看懂,也不要跟我说没必要解释的什么的了,因为毕竟要让大家都弄明白。 言归正传,今天我们来详细的讲一下DownloadManager

  • http://www.trinea.cn/android/android-downloadmanager/   http://www.trinea.cn/android/android-downloadmanager-pro/ 转载于:https://www.cnblogs.com/soaringEveryday/articles/4135204.html

  • ##简述 DownloadManger是android 2.3(API 9)开始提供的系统服务,用于处理长时间的下载操作。应用场景是客户端请求一个URL地址去下载一个目标文件。DownloadManger可以构建一个后台下载服务,在发生故障或连接更改、重新启动系统等情况后,处理HTTP连接并重试下载。 主要的接口和类: 1、内部类DownloadManager.Query,这个类可以用于过滤Dow

  • LogUtil-工具类 是专门Log日志打印 和 Toast的提示,的公共方法 package common.library.utils; import android.content.Context; import android.util.Log; import android.widget.Toast; /** * @Author Liudeli * @Describe:Log日志级别打印相

  • 嗷,这个android系统下载管理DownloadManager功能还是蛮强大的。虽然老大只是让我做一个下载工具类给他们使用,但是想加深一下印象,接下来是摘抄笔记,以后也要自己再看看不要又忘了。 一.DownloadManager简单介绍 DownloadManager是系统开放给第三方应用使用的类,包含两个静态内部类DownloadManager.Query和DownloadManager.Re

  • 描述,系统提供的DownloadManager的工作原理,及如何实现下载、暂停、继续下载、查询等操作。 参考文献: 基本使用:http://www.jianshu.com/p/7ad92b3d9069 工作原理:http://blog.csdn.net/garment1991/article/details/54178557 如何实现暂停:http://www.trinea.cn/android/

  • 最近在弄android整包下载,使用到Downloadmanager  下载和安装,新手尝试,欢迎大家指正。 关于 FileProvider 百度一下很简单。 public class ApkDownloadMgr { //下载器 private DownloadManager m_dMgr; private Context m_context; private long m_downlo

  • 使用命令react-native run-android构建我的Android应用程序时遇到问题.得到此错误: Nicholass-MacBook-Pro:MonsterHunterWorld nicholaslie$react-native run-android Scanning folders for symlinks in /Users/nicholaslie/Documents/Pers

 相关资料
  • Xtreme Download Manager是一个功能强大的工具,可以将下载速度提高到500%,保存来自YouTube,DailyMotion,Facebook,Vimeo,Google Video和1000多个其他网站的流式视频,恢复断/死下载,安排和转换下载。 XDM与Google Chrome,Mozilla Firefox Quantum,Opera,Vivaldi以及其他基于Chrum

  • Free Download Manager(简称 FDM)是一款跨平台下载工具。 主要特性 快速、安全且高效地下载 支持服务器 支持 HTTP/HTTPS/FTP/BT 现代化的友好界面,简洁无广告 支持 Windows 和 macOS 支持 BT 和断点续传 支持多语言 支持下载加速

  • 开放下载管理器 - 快速而容易的获得 Open Download Manager 象征着开放与自由, 同时我们又渴望像海燕一样快速敏捷 Open Download Manager 中,英文版, 采用 GNU GPLv3, 现已支持 BitTorrent, 即将支持 eMule/eDonkey Open Download Manager (ODM)主界面, 中,英文双语可互换

  • 这是一个使用了 ASIHTTPRequest 类开发的下载管理器,可在后台下载文件,可同时下载多个文件,可在应用退出时恢复下载。

  • 一、说明 Android network manager based on Android Volley, JSON, XML, Map, RequestMap(with file) support. AndroidVolley,Android Volley核心库及扩展工程。 AndroidVolleySample,网络请求工具示例工程。 Release,AndroidVolley jar包。 二

  • Android Applications Manager 是一个第三方的 Android 手机应用程序管理工具,你可以直接在 PC 上对手机的应用进行管理。