Merge branch 'v_3.0' of github.com:AriaLyy/Aria into v_3.0
This commit is contained in:
2
.idea/modules.xml
generated
2
.idea/modules.xml
generated
@ -2,8 +2,8 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Aria/Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Aria.iml" filepath="$PROJECT_DIR$/Aria.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Aria/Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Aria/Aria-Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria-Aria.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/AriaPrj.iml" filepath="$PROJECT_DIR$/AriaPrj.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
|
@ -43,7 +43,6 @@ import com.arialyy.aria.core.upload.UploadTask;
|
||||
* .load(DOWNLOAD_URL) //下载地址,必填
|
||||
* //文件保存路径,必填
|
||||
* .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
||||
* .setDownloadName("test.apk") //文件名,必填
|
||||
* .start();
|
||||
* </code>
|
||||
* <code>
|
||||
|
@ -32,8 +32,7 @@ final class DownloadStateConstance {
|
||||
boolean isCancel = false;
|
||||
boolean isStop = false;
|
||||
|
||||
DownloadStateConstance(int num) {
|
||||
THREAD_NUM = num;
|
||||
DownloadStateConstance() {
|
||||
}
|
||||
|
||||
void cleanState() {
|
||||
@ -46,7 +45,7 @@ final class DownloadStateConstance {
|
||||
FAIL_NUM = 0;
|
||||
}
|
||||
|
||||
void setThreadNum(int threadNum){
|
||||
void setThreadNum(int threadNum) {
|
||||
THREAD_NUM = threadNum;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import com.arialyy.aria.core.RequestEnum;
|
||||
import com.arialyy.aria.core.inf.AbsTarget;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
import com.arialyy.aria.util.CheckUtil;
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -35,6 +36,14 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
|
||||
taskEntity = new DownloadTaskEntity(entity);
|
||||
}
|
||||
|
||||
@Override public void pause() {
|
||||
super.pause();
|
||||
}
|
||||
|
||||
@Override public void resume() {
|
||||
super.resume();
|
||||
}
|
||||
|
||||
/**
|
||||
* 给url请求添加头部
|
||||
*
|
||||
@ -73,13 +82,16 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
|
||||
if (TextUtils.isEmpty(downloadPath)) {
|
||||
throw new IllegalArgumentException("文件保持路径不能为null");
|
||||
}
|
||||
File file = new File(downloadPath);
|
||||
entity.setDownloadPath(downloadPath);
|
||||
entity.setFileName(file.getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文件名
|
||||
*/
|
||||
@Deprecated
|
||||
public DownloadTarget setDownloadName(@NonNull String downloadName) {
|
||||
if (TextUtils.isEmpty(downloadName)) {
|
||||
throw new IllegalArgumentException("文件名不能为null");
|
||||
@ -88,7 +100,6 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
private DownloadEntity getDownloadEntity(String downloadUrl) {
|
||||
CheckUtil.checkDownloadUrl(downloadUrl);
|
||||
return DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?", downloadUrl);
|
||||
|
@ -39,8 +39,11 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
/**
|
||||
* 线程数
|
||||
*/
|
||||
private final int THREAD_NUM;
|
||||
private static final long SUB_LEN = 1024 * 100;
|
||||
private int THREAD_NUM;
|
||||
/**
|
||||
* 小于1m的文件不启用多线程
|
||||
*/
|
||||
private static final long SUB_LEN = 1024 * 1024;
|
||||
//下载监听
|
||||
private IDownloadListener mListener;
|
||||
private int mConnectTimeOut = 5000 * 4; //连接超时时间
|
||||
@ -69,7 +72,7 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
mListener = downloadListener;
|
||||
THREAD_NUM = threadNum;
|
||||
mFixedThreadPool = Executors.newFixedThreadPool(Integer.MAX_VALUE);
|
||||
mConstance = new DownloadStateConstance(THREAD_NUM);
|
||||
mConstance = new DownloadStateConstance();
|
||||
init();
|
||||
}
|
||||
|
||||
@ -246,51 +249,17 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
* 处理断点
|
||||
*/
|
||||
private void handleBreakpoint(HttpURLConnection conn) throws IOException {
|
||||
|
||||
//不支持断点只能单线程下载
|
||||
if (!isSupportBreakpoint) {
|
||||
ConfigEntity entity = new ConfigEntity();
|
||||
long len = conn.getContentLength();
|
||||
entity.FILE_SIZE = len;
|
||||
entity.DOWNLOAD_URL = mDownloadEntity.getDownloadUrl();
|
||||
entity.TEMP_FILE = mDownloadFile;
|
||||
entity.THREAD_ID = 0;
|
||||
entity.START_LOCATION = 0;
|
||||
entity.END_LOCATION = entity.FILE_SIZE;
|
||||
entity.CONFIG_FILE_PATH = mConfigFile.getPath();
|
||||
entity.isSupportBreakpoint = isSupportBreakpoint;
|
||||
entity.DOWNLOAD_TASK_ENTITY = mDownloadTaskEntity;
|
||||
SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity);
|
||||
mFixedThreadPool.execute(task);
|
||||
mListener.onPostPre(len);
|
||||
mListener.onStart(0);
|
||||
handleNoSupportBreakpointDownload(conn);
|
||||
return;
|
||||
}
|
||||
int fileLength = conn.getContentLength();
|
||||
//必须建一个文件
|
||||
CommonUtil.createFile(mDownloadFile.getPath());
|
||||
BufferedRandomAccessFile file =
|
||||
new BufferedRandomAccessFile(new File(mDownloadFile.getPath()), "rwd", 8192);
|
||||
//设置文件长度
|
||||
file.setLength(fileLength);
|
||||
mListener.onPostPre(fileLength);
|
||||
//分配每条线程的下载区间
|
||||
Properties pro = null;
|
||||
pro = CommonUtil.loadConfig(mConfigFile);
|
||||
if (pro.isEmpty()) {
|
||||
isNewTask = true;
|
||||
} else {
|
||||
for (int i = 0; i < THREAD_NUM; i++) {
|
||||
if (pro.getProperty(mDownloadFile.getName() + "_record_" + i) == null) {
|
||||
Object state = pro.getProperty(mDownloadFile.getName() + "_state_" + i);
|
||||
if (state != null && Integer.parseInt(state + "") == 1) {
|
||||
continue;
|
||||
}
|
||||
isNewTask = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (fileLength < SUB_LEN) {
|
||||
THREAD_NUM = 1;
|
||||
mConstance.THREAD_NUM = THREAD_NUM;
|
||||
}
|
||||
Properties pro = createConfigFile(fileLength);
|
||||
int blockSize = fileLength / THREAD_NUM;
|
||||
int[] recordL = new int[THREAD_NUM];
|
||||
int rl = 0;
|
||||
@ -301,19 +270,7 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
long startL = i * blockSize, endL = (i + 1) * blockSize;
|
||||
Object state = pro.getProperty(mDownloadFile.getName() + "_state_" + i);
|
||||
if (state != null && Integer.parseInt(state + "") == 1) { //该线程已经完成
|
||||
mConstance.CURRENT_LOCATION += endL - startL;
|
||||
Log.d(TAG, "++++++++++ 线程_" + i + "_已经下载完成 ++++++++++");
|
||||
mConstance.COMPLETE_THREAD_NUM++;
|
||||
mConstance.STOP_NUM++;
|
||||
mConstance.CANCEL_NUM++;
|
||||
if (mConstance.isComplete()) {
|
||||
if (mConfigFile.exists()) {
|
||||
mConfigFile.delete();
|
||||
}
|
||||
mListener.onComplete();
|
||||
mConstance.isDownloading = false;
|
||||
return;
|
||||
}
|
||||
if (resumeRecordLocation(i, startL, endL)) return;
|
||||
continue;
|
||||
}
|
||||
//分配下载位置
|
||||
@ -338,6 +295,89 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
//如果整个文件的大小不为线程个数的整数倍,则最后一个线程的结束位置即为文件的总长度
|
||||
endL = fileLength;
|
||||
}
|
||||
addSingleTask(i, startL, endL, fileLength);
|
||||
}
|
||||
startSingleTask(recordL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理不支持断点的下载
|
||||
*/
|
||||
private void handleNoSupportBreakpointDownload(HttpURLConnection conn){
|
||||
ConfigEntity entity = new ConfigEntity();
|
||||
long len = conn.getContentLength();
|
||||
entity.FILE_SIZE = len;
|
||||
entity.DOWNLOAD_URL = mDownloadEntity.getDownloadUrl();
|
||||
entity.TEMP_FILE = mDownloadFile;
|
||||
entity.THREAD_ID = 0;
|
||||
entity.START_LOCATION = 0;
|
||||
entity.END_LOCATION = entity.FILE_SIZE;
|
||||
entity.CONFIG_FILE_PATH = mConfigFile.getPath();
|
||||
entity.isSupportBreakpoint = isSupportBreakpoint;
|
||||
entity.DOWNLOAD_TASK_ENTITY = mDownloadTaskEntity;
|
||||
SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity);
|
||||
mFixedThreadPool.execute(task);
|
||||
mListener.onPostPre(len);
|
||||
mListener.onStart(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建配置文件
|
||||
*/
|
||||
private Properties createConfigFile(long fileLength) throws IOException {
|
||||
Properties pro = null;
|
||||
//必须建一个文件
|
||||
CommonUtil.createFile(mDownloadFile.getPath());
|
||||
BufferedRandomAccessFile file =
|
||||
new BufferedRandomAccessFile(new File(mDownloadFile.getPath()), "rwd", 8192);
|
||||
//设置文件长度
|
||||
file.setLength(fileLength);
|
||||
mListener.onPostPre(fileLength);
|
||||
//分配每条线程的下载区间
|
||||
pro = CommonUtil.loadConfig(mConfigFile);
|
||||
if (pro.isEmpty()) {
|
||||
isNewTask = true;
|
||||
} else {
|
||||
for (int i = 0; i < THREAD_NUM; i++) {
|
||||
if (pro.getProperty(mDownloadFile.getName() + "_record_" + i) == null) {
|
||||
Object state = pro.getProperty(mDownloadFile.getName() + "_state_" + i);
|
||||
if (state != null && Integer.parseInt(state + "") == 1) {
|
||||
continue;
|
||||
}
|
||||
isNewTask = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return pro;
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复记录地址
|
||||
*
|
||||
* @return true 表示下载完成
|
||||
*/
|
||||
private boolean resumeRecordLocation(int i, long startL, long endL) {
|
||||
mConstance.CURRENT_LOCATION += endL - startL;
|
||||
Log.d(TAG, "++++++++++ 线程_" + i + "_已经下载完成 ++++++++++");
|
||||
mConstance.COMPLETE_THREAD_NUM++;
|
||||
mConstance.STOP_NUM++;
|
||||
mConstance.CANCEL_NUM++;
|
||||
if (mConstance.isComplete()) {
|
||||
if (mConfigFile.exists()) {
|
||||
mConfigFile.delete();
|
||||
}
|
||||
mListener.onComplete();
|
||||
mConstance.isDownloading = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建单线程任务
|
||||
*/
|
||||
private void addSingleTask(int i, long startL, long endL, long fileLength) {
|
||||
ConfigEntity entity = new ConfigEntity();
|
||||
entity.FILE_SIZE = fileLength;
|
||||
entity.DOWNLOAD_URL = mDownloadEntity.getDownloadUrl();
|
||||
@ -351,6 +391,11 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity);
|
||||
mTask.put(i, task);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动单线程下载任务
|
||||
*/
|
||||
private void startSingleTask(int[] recordL) {
|
||||
if (mConstance.CURRENT_LOCATION > 0) {
|
||||
mListener.onResume(mConstance.CURRENT_LOCATION);
|
||||
} else {
|
||||
@ -370,14 +415,14 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
*/
|
||||
final static class ConfigEntity {
|
||||
//文件大小
|
||||
long FILE_SIZE;
|
||||
String DOWNLOAD_URL;
|
||||
int THREAD_ID;
|
||||
long FILE_SIZE;
|
||||
long START_LOCATION;
|
||||
long END_LOCATION;
|
||||
File TEMP_FILE;
|
||||
boolean isSupportBreakpoint = true;
|
||||
String DOWNLOAD_URL;
|
||||
String CONFIG_FILE_PATH;
|
||||
DownloadTaskEntity DOWNLOAD_TASK_ENTITY;
|
||||
boolean isSupportBreakpoint = true;
|
||||
}
|
||||
}
|
@ -141,7 +141,7 @@ public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity>
|
||||
/**
|
||||
* 停止下载
|
||||
*/
|
||||
public void stop() {
|
||||
protected void pause() {
|
||||
AriaManager.getInstance(AriaManager.APP)
|
||||
.setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_STOP))
|
||||
.exe();
|
||||
@ -150,7 +150,7 @@ public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity>
|
||||
/**
|
||||
* 恢复下载
|
||||
*/
|
||||
public void resume() {
|
||||
protected void resume() {
|
||||
AriaManager.getInstance(AriaManager.APP)
|
||||
.setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_START))
|
||||
.exe();
|
||||
@ -168,7 +168,7 @@ public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity>
|
||||
/**
|
||||
* 重新下载
|
||||
*/
|
||||
public void reStart() {
|
||||
void reStart() {
|
||||
cancel();
|
||||
start();
|
||||
}
|
||||
|
40
DownloadApi.md
Normal file
40
DownloadApi.md
Normal file
@ -0,0 +1,40 @@
|
||||
## 关于Aria,你还需要知道的一些东西
|
||||
- 设置下载任务数,Aria默认下载任务为**2**
|
||||
|
||||
```java
|
||||
Aria.get(getContext()).setMaxDownloadNum(num);
|
||||
```
|
||||
- 停止所有下载
|
||||
|
||||
```java
|
||||
Aria.get(this).stopAllTask();
|
||||
```
|
||||
- 设置失败重试次数,从事次数不能少于 1
|
||||
|
||||
```java
|
||||
Aria.get(this).setReTryNum(10);
|
||||
```
|
||||
- 设置失败重试间隔,重试间隔不能小于 5000ms
|
||||
|
||||
```java
|
||||
Aria.get(this).setReTryInterval(5000);
|
||||
```
|
||||
- 设置是否打开广播,如果你需要在Service后台获取下载完成情况,那么你需要打开Aria广播,[Aria广播配置](https://github.com/AriaLyy/Aria/blob/v_2.0/BroadCast.md)
|
||||
|
||||
```java
|
||||
Aria.get(this).openBroadcast(true);
|
||||
```
|
||||
|
||||
## https证书配置
|
||||
+ 将你的证书导入`assets`目录
|
||||
+ 调用以下代码配置ca证书相关信息
|
||||
|
||||
```java
|
||||
/**
|
||||
* 设置CA证书信息
|
||||
*
|
||||
* @param caAlias ca证书别名
|
||||
* @param caPath assets 文件夹下的ca证书完整路径
|
||||
*/
|
||||
Aria.get(this).setCAInfo("caAlias","caPath");
|
||||
```
|
185
README.md
185
README.md
@ -1,16 +1,17 @@
|
||||
# Aria
|
||||
</br>
|
||||
Aria,致力于让下载傻瓜化</br>
|
||||
Aria,让上传、下载更容易实现</br>
|
||||
+ Aria有以下特点:
|
||||
- 简单
|
||||
- 可在Dialog、popupWindow等组件中使用
|
||||
- 可自定义是否使用广播
|
||||
- 支持多线程、多任务下载
|
||||
- 支持任务自动切换
|
||||
- 支持下载速度直接获取
|
||||
- 支持多任务自动调度
|
||||
- 可以直接获取速度
|
||||
- 支持https地址下载
|
||||
|
||||
[Aria怎样使用?](#使用)
|
||||
Aria怎样使用?
|
||||
* [下载](#使用)
|
||||
* [上传](#上传)
|
||||
|
||||
如果你觉得Aria对你有帮助,您的star和issues将是对我最大支持.`^_^`
|
||||
|
||||
@ -24,112 +25,114 @@ compile 'com.arialyy.aria:Aria:2.4.0'
|
||||

|
||||

|
||||
|
||||
## 性能展示
|
||||

|
||||
## 性能
|
||||

|
||||
|
||||
***
|
||||
## 使用
|
||||
### 一、添加权限
|
||||
由于Aria涉及到文件和网络的操作,因此需要你在manifest文件中添加以下权限
|
||||
```xml
|
||||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<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() {
|
||||
|
||||
## 使用Aria进行下载
|
||||
* 添加任务(不进行下载),当其他下载任务完成时,将自动下载等待中的任务
|
||||
```java
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") //文件保存路径
|
||||
.add();
|
||||
```
|
||||
|
||||
* 下载
|
||||
|
||||
```java
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL) //读取下载地址
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") //设置文件保存的完整路径
|
||||
.start(); //启动下载
|
||||
```
|
||||
* 暂停
|
||||
|
||||
```java
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
```
|
||||
* 恢复下载
|
||||
|
||||
```java
|
||||
Aria.download(this).load(DOWNLOAD_URL).resume();
|
||||
```
|
||||
* 取消下载
|
||||
|
||||
```java
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
```
|
||||
|
||||
### 二、如果你希望读取下载进度或下载信息,那么你需要创建事件类,并在onResume(Activity、Fragment)或构造函数(Dialog、PopupWindow),将该事件类注册到Aria管理器。
|
||||
* 创建事件类
|
||||
|
||||
```java
|
||||
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);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
* 将事件注册到Aria
|
||||
|
||||
```java
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.whit(this).addSchedulerListener(new MySchedulerListener());
|
||||
}
|
||||
```
|
||||
### 四、通过下载链接,你还能使用Aria执行很多操作,如:
|
||||
Aria支持https下载,如果你希望使用自己的ca证书,那么你需要进行[Aria https证书配置](#https证书配置)
|
||||
- 添加任务(不进行下载)
|
||||
```
|
||||
|
||||
### 关于下载的其它api
|
||||
[Download API]()
|
||||
|
||||
**tips:为了防止内存泄露的情况,事件类需要使用staic进行修饰**
|
||||
|
||||
## 上传
|
||||
* 添加任务(只添加,不上传)
|
||||
|
||||
```java
|
||||
Aria.whit(this).load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk") //文件保存路径,必填
|
||||
.setDownloadName("test.apk") //文件名,必填
|
||||
Aria.upload(this)
|
||||
.load(filePath) //文件路径
|
||||
.setUploadUrl(uploadUrl) //上传路径
|
||||
.setAttachment(fileKey) //服务器读取文件的key
|
||||
.add();
|
||||
```
|
||||
- 启动下载
|
||||
|
||||
* 上传
|
||||
|
||||
```java
|
||||
Aria.whit(this).load(DOWNLOAD_URL).start();
|
||||
Aria.upload(this)
|
||||
.load(filePath) //文件路径
|
||||
.setUploadUrl(uploadUrl) //上传路径
|
||||
.setAttachment(fileKey) //服务器读取文件的key
|
||||
.start();
|
||||
```
|
||||
- 暂停下载
|
||||
* 取消上传
|
||||
|
||||
```java
|
||||
Aria.whit(this).load(DOWNLOAD_URL).stop();
|
||||
```
|
||||
- 恢复下载
|
||||
|
||||
```java
|
||||
Aria.whit(this).load(DOWNLOAD_URL).resume();
|
||||
```
|
||||
- 取消下载
|
||||
|
||||
```java
|
||||
Aria.whit(this).load(DOWNLOAD_URL).cancel();
|
||||
```
|
||||
- 获取当前下载进度
|
||||
|
||||
```java
|
||||
Aria.whit(this).load(DOWNLOAD_URL).getCurrentProgress();
|
||||
```
|
||||
- 获取文件大小
|
||||
|
||||
```java
|
||||
Aria.whit(this).load(DOWNLOAD_URL).getFileSize();
|
||||
```
|
||||
|
||||
### 五、关于Aria,你还需要知道的一些东西
|
||||
- 设置下载任务数,Aria默认下载任务为**2**
|
||||
|
||||
```java
|
||||
Aria.get(getContext()).setMaxDownloadNum(num);
|
||||
```
|
||||
- 停止所有下载
|
||||
|
||||
```java
|
||||
Aria.get(this).stopAllTask();
|
||||
```
|
||||
- 设置失败重试次数,从事次数不能少于 1
|
||||
|
||||
```java
|
||||
Aria.get(this).setReTryNum(10);
|
||||
```
|
||||
- 设置失败重试间隔,重试间隔不能小于 5000ms
|
||||
|
||||
```java
|
||||
Aria.get(this).setReTryInterval(5000);
|
||||
```
|
||||
- 设置是否打开广播,如果你需要在Service后台获取下载完成情况,那么你需要打开Aria广播,[Aria广播配置](https://github.com/AriaLyy/Aria/blob/v_2.0/BroadCast.md)
|
||||
|
||||
```java
|
||||
Aria.get(this).openBroadcast(true);
|
||||
```
|
||||
|
||||
### https证书配置
|
||||
+ 将你的证书导入`assets`目录
|
||||
+ 调用以下代码配置ca证书相关信息
|
||||
|
||||
```java
|
||||
/**
|
||||
* 设置CA证书信息
|
||||
*
|
||||
* @param caAlias ca证书别名
|
||||
* @param caPath assets 文件夹下的ca证书完整路径
|
||||
*/
|
||||
Aria.get(this).setCAInfo("caAlias","caPath");
|
||||
Aria.upload(this)
|
||||
.load(filePath)
|
||||
.cancel();
|
||||
```
|
||||
|
||||
***
|
||||
|
@ -62,11 +62,10 @@ public class DownloadDialog extends AbsDialog {
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk")
|
||||
.setDownloadName("daialog.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
|
@ -64,11 +64,10 @@ public class DownloadPopupWindow extends AbsPopupWindow {
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk")
|
||||
.setDownloadName("daialog.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
|
@ -47,7 +47,7 @@ public class SimpleNotification {
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
Aria.download(mContext).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(mContext).load(DOWNLOAD_URL).pause();
|
||||
}
|
||||
|
||||
private static class DownloadCallback extends Aria.DownloadSchedulerListener {
|
||||
|
@ -227,12 +227,11 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
||||
.setDownloadName("test.apk")
|
||||
.start();
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
}
|
||||
|
||||
private void cancel() {
|
||||
|
@ -62,7 +62,7 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
|
@ -187,7 +187,7 @@ final class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter
|
||||
}
|
||||
|
||||
private void stop(DownloadEntity entity) {
|
||||
Aria.download(getContext()).load(entity).stop();
|
||||
Aria.download(getContext()).load(entity).pause();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ public class UploadActivity extends BaseActivity<ActivityUploadMeanBinding> {
|
||||
}
|
||||
|
||||
@OnClick(R.id.stop) void stop() {
|
||||
Aria.upload(this).load(FILE_PATH).stop();
|
||||
Aria.upload(this).load(FILE_PATH).cancel();
|
||||
}
|
||||
|
||||
@OnClick(R.id.remove) void remove() {
|
||||
|
Reference in New Issue
Block a user