|
|
@ -1,16 +1,17 @@ |
|
|
|
# Aria |
|
|
|
# Aria |
|
|
|
![图标](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/app/src/main/res/mipmap-hdpi/ic_launcher.png)</br> |
|
|
|
![图标](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/app/src/main/res/mipmap-hdpi/ic_launcher.png)</br> |
|
|
|
Aria,致力于让下载傻瓜化</br> |
|
|
|
Aria,让上传、下载更容易实现</br> |
|
|
|
+ Aria有以下特点: |
|
|
|
+ Aria有以下特点: |
|
|
|
- 简单 |
|
|
|
- 简单 |
|
|
|
- 可在Dialog、popupWindow等组件中使用 |
|
|
|
- 可在Dialog、popupWindow等组件中使用 |
|
|
|
- 可自定义是否使用广播 |
|
|
|
|
|
|
|
- 支持多线程、多任务下载 |
|
|
|
- 支持多线程、多任务下载 |
|
|
|
- 支持任务自动切换 |
|
|
|
- 支持多任务自动调度 |
|
|
|
- 支持下载速度直接获取 |
|
|
|
- 可以直接获取速度 |
|
|
|
- 支持https地址下载 |
|
|
|
- 支持https地址下载 |
|
|
|
|
|
|
|
|
|
|
|
[Aria怎样使用?](#使用) |
|
|
|
Aria怎样使用? |
|
|
|
|
|
|
|
* [下载](#使用) |
|
|
|
|
|
|
|
* [上传](#上传) |
|
|
|
|
|
|
|
|
|
|
|
如果你觉得Aria对你有帮助,您的star和issues将是对我最大支持.`^_^` |
|
|
|
如果你觉得Aria对你有帮助,您的star和issues将是对我最大支持.`^_^` |
|
|
|
|
|
|
|
|
|
|
@ -24,113 +25,115 @@ compile 'com.arialyy.aria:Aria:2.4.0' |
|
|
|
![多任务下载](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/img/download_img.gif) |
|
|
|
![多任务下载](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/img/download_img.gif) |
|
|
|
![Dialog使用](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/img/dialog_use.gif "") |
|
|
|
![Dialog使用](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/img/dialog_use.gif "") |
|
|
|
|
|
|
|
|
|
|
|
## 性能展示 |
|
|
|
## 性能 |
|
|
|
![性能展示](https://github.com/AriaLyy/DownloadUtil/blob/v_2.0/img/performance.png) |
|
|
|
![性能展示](https://github.com/AriaLyy/DownloadUtil/blob/master/img/performance.png) |
|
|
|
|
|
|
|
|
|
|
|
*** |
|
|
|
*** |
|
|
|
## 使用 |
|
|
|
## 使用 |
|
|
|
### 一、添加权限 |
|
|
|
由于Aria涉及到文件和网络的操作,因此需要你在manifest文件中添加以下权限 |
|
|
|
```xml |
|
|
|
```xml |
|
|
|
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> |
|
|
|
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> |
|
|
|
<uses-permission android:name="android.permission.INTERNET"/> |
|
|
|
<uses-permission android:name="android.permission.INTERNET"/> |
|
|
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> |
|
|
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> |
|
|
|
``` |
|
|
|
``` |
|
|
|
### 二、只需要以下参数,你便能很简单的使用Aria下载文件了 |
|
|
|
|
|
|
|
```java |
|
|
|
|
|
|
|
Aria.whit(this) |
|
|
|
|
|
|
|
.load(DOWNLOAD_URL) //下载地址,必填 |
|
|
|
|
|
|
|
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") //文件保存路径,必填 |
|
|
|
|
|
|
|
.setDownloadName("test.apk") //文件名,必填 |
|
|
|
|
|
|
|
.start(); |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
### 三、为了能接收到Aria传递的数据,你需要把你的Activity或fragment注册到Aria管理器中,注册的方式很简单,在onResume |
|
|
|
|
|
|
|
```java |
|
|
|
|
|
|
|
@Override protected void onResume() { |
|
|
|
|
|
|
|
super.onResume(); |
|
|
|
|
|
|
|
Aria.whit(this).addSchedulerListener(new MySchedulerListener()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
### 四、通过下载链接,你还能使用Aria执行很多操作,如: |
|
|
|
|
|
|
|
Aria支持https下载,如果你希望使用自己的ca证书,那么你需要进行[Aria https证书配置](#https证书配置) |
|
|
|
|
|
|
|
- 添加任务(不进行下载) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 使用Aria进行下载 |
|
|
|
|
|
|
|
* 添加任务(不进行下载),当其他下载任务完成时,将自动下载等待中的任务 |
|
|
|
```java |
|
|
|
```java |
|
|
|
Aria.whit(this).load(DOWNLOAD_URL) |
|
|
|
Aria.download(this) |
|
|
|
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") //文件保存路径,必填 |
|
|
|
.load(DOWNLOAD_URL) |
|
|
|
.setDownloadName("test.apk") //文件名,必填 |
|
|
|
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") //文件保存路径 |
|
|
|
.add(); |
|
|
|
.add(); |
|
|
|
``` |
|
|
|
|
|
|
|
- 启动下载 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
|
|
|
|
Aria.whit(this).load(DOWNLOAD_URL).start(); |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
- 暂停下载 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
|
|
|
|
Aria.whit(this).load(DOWNLOAD_URL).stop(); |
|
|
|
|
|
|
|
``` |
|
|
|
``` |
|
|
|
- 恢复下载 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
* 下载 |
|
|
|
Aria.whit(this).load(DOWNLOAD_URL).resume(); |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
- 取消下载 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
```java |
|
|
|
Aria.whit(this).load(DOWNLOAD_URL).cancel(); |
|
|
|
Aria.download(this) |
|
|
|
|
|
|
|
.load(DOWNLOAD_URL) //读取下载地址 |
|
|
|
|
|
|
|
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") //设置文件保存的完整路径 |
|
|
|
|
|
|
|
.start(); //启动下载 |
|
|
|
``` |
|
|
|
``` |
|
|
|
- 获取当前下载进度 |
|
|
|
* 暂停 |
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
```java |
|
|
|
Aria.whit(this).load(DOWNLOAD_URL).getCurrentProgress(); |
|
|
|
Aria.download(this).load(DOWNLOAD_URL).pause(); |
|
|
|
``` |
|
|
|
``` |
|
|
|
- 获取文件大小 |
|
|
|
* 恢复下载 |
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
```java |
|
|
|
Aria.whit(this).load(DOWNLOAD_URL).getFileSize(); |
|
|
|
Aria.download(this).load(DOWNLOAD_URL).resume(); |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
* 取消下载 |
|
|
|
### 五、关于Aria,你还需要知道的一些东西 |
|
|
|
|
|
|
|
- 设置下载任务数,Aria默认下载任务为**2** |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
```java |
|
|
|
Aria.get(getContext()).setMaxDownloadNum(num); |
|
|
|
Aria.download(this).load(DOWNLOAD_URL).cancel(); |
|
|
|
``` |
|
|
|
``` |
|
|
|
- 停止所有下载 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
### 二、如果你希望读取下载进度或下载信息,那么你需要创建事件类,并在onResume(Activity、Fragment)或构造函数(Dialog、PopupWindow),将该事件类注册到Aria管理器。 |
|
|
|
Aria.get(this).stopAllTask(); |
|
|
|
* 创建事件类 |
|
|
|
``` |
|
|
|
|
|
|
|
- 设置失败重试次数,从事次数不能少于 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
```java |
|
|
|
Aria.get(this).setReTryNum(10); |
|
|
|
final static class MySchedulerListener extends Aria.DownloadSchedulerListener{ |
|
|
|
|
|
|
|
@Override public void onTaskPre(DownloadTask task) { |
|
|
|
|
|
|
|
super.onTaskPre(task); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public void onTaskStop(DownloadTask task) { |
|
|
|
|
|
|
|
super.onTaskStop(task); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public void onTaskCancel(DownloadTask task) { |
|
|
|
|
|
|
|
super.onTaskCancel(task); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public void onTaskRunning(DownloadTask task) { |
|
|
|
|
|
|
|
super.onTaskRunning(task); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
``` |
|
|
|
``` |
|
|
|
- 设置失败重试间隔,重试间隔不能小于 5000ms |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
* 将事件注册到Aria |
|
|
|
Aria.get(this).setReTryInterval(5000); |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
- 设置是否打开广播,如果你需要在Service后台获取下载完成情况,那么你需要打开Aria广播,[Aria广播配置](https://github.com/AriaLyy/Aria/blob/v_2.0/BroadCast.md) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
```java |
|
|
|
Aria.get(this).openBroadcast(true); |
|
|
|
@Override protected void onResume() { |
|
|
|
|
|
|
|
super.onResume(); |
|
|
|
|
|
|
|
Aria.whit(this).addSchedulerListener(new MySchedulerListener()); |
|
|
|
|
|
|
|
} |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
### https证书配置 |
|
|
|
### 关于下载的其它api |
|
|
|
+ 将你的证书导入`assets`目录 |
|
|
|
[Download API]() |
|
|
|
+ 调用以下代码配置ca证书相关信息 |
|
|
|
|
|
|
|
|
|
|
|
**tips:为了防止内存泄露的情况,事件类需要使用staic进行修饰** |
|
|
|
```java |
|
|
|
|
|
|
|
/** |
|
|
|
## 上传 |
|
|
|
* 设置CA证书信息 |
|
|
|
* 添加任务(只添加,不上传) |
|
|
|
* |
|
|
|
|
|
|
|
* @param caAlias ca证书别名 |
|
|
|
```java |
|
|
|
* @param caPath assets 文件夹下的ca证书完整路径 |
|
|
|
Aria.upload(this) |
|
|
|
*/ |
|
|
|
.load(filePath) //文件路径 |
|
|
|
Aria.get(this).setCAInfo("caAlias","caPath"); |
|
|
|
.setUploadUrl(uploadUrl) //上传路径 |
|
|
|
``` |
|
|
|
.setAttachment(fileKey) //服务器读取文件的key |
|
|
|
|
|
|
|
.add(); |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 上传 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
|
|
|
|
Aria.upload(this) |
|
|
|
|
|
|
|
.load(filePath) //文件路径 |
|
|
|
|
|
|
|
.setUploadUrl(uploadUrl) //上传路径 |
|
|
|
|
|
|
|
.setAttachment(fileKey) //服务器读取文件的key |
|
|
|
|
|
|
|
.start(); |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
* 取消上传 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
|
|
|
|
Aria.upload(this) |
|
|
|
|
|
|
|
.load(filePath) |
|
|
|
|
|
|
|
.cancel(); |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
*** |
|
|
|
*** |
|
|
|
## 开发日志 |
|
|
|
## 开发日志 |
|
|
|