You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Android-Download/README.md

305 lines
11 KiB

# Aria
7 years ago
![图标](https://github.com/AriaLyy/DownloadUtil/blob/master/app/src/main/res/mipmap-hdpi/ic_launcher.png)</br>
## [中文文档](https://github.com/AriaLyy/Aria/blob/master/README.md)
Aria project is from the moment taht the work encountered in a file download management needs adn i was tortured at the time of the pain.</br>
Since then i have a idea which is to program a simple and easy to use,stable and efficient download framework.
Aria experienced 1.0 to 3.0 development, be more and more close to the original set by the target.
Aria has the following characteristics:
+ simple and convenient
- can be used in Activity, Service, Fragment, Dialog, popupWindow, Notification and other components
- support the task of automatic scheduling, the user does not need to care about the state of the task switch logic
7 years ago
- [Through the Aria event, it is easy to get the download status of the current download task](#downloadStatus)
- [a code plus can get the current download speed](#interface)
- [a code can be dynamically set the maximum number of downloads](#parameters)
- [code to achieve speed limit](#interface)
7 years ago
- [It is easy to modify the number of download threads by modifying the configuration file](https://github.com/AriaLyy/Aria/blob/master/app/src/main/assets/aria_config.xml)
7 years ago
- [priority to download a task](#interface)
7 years ago
+ Support https address download
- It is easy to set the CA certificate information in the configuration file
+ Support 300,301,302 redirect download link download
+ Support upload operation
How do we to use Aria?
* [download](#Using)
* [upload](#Upload)
If you feel that Aria is helpful to you, your star and issues will be the greatest support for me.`^_^`
## Download
8 years ago
[![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion)
[![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion)
8 years ago
```java
8 years ago
compile 'com.arialyy.aria:aria-core:3.2.0'
annotationProcessor 'com.arialyy.aria:aria-compiler:3.2.0'
8 years ago
```
7 years ago
## For example
![Multi-task download](https://github.com/AriaLyy/DownloadUtil/blob/master/img/download_img.gif)
![download speed limit](https://github.com/AriaLyy/DownloadUtil/blob/master/img/max_speed.gif)
8 years ago
7 years ago
## performance
![Performance display](https://github.com/AriaLyy/DownloadUtil/blob/master/img/performance.png)
8 years ago
***
7 years ago
## Using
Since Aria involves the operation of files and networks, you need to add the following permissions to the manifest file.
```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"/>
```
8 years ago
7 years ago
## Use Aria to download
* Add a task (do not download), when other download tasks are completed, will automatically download the waiting task
8 years ago
```java
8 years ago
Aria.download(this)
.load(DOWNLOAD_URL)
7 years ago
.setDownloadPath(DOWNLOAD_PATH) //file save path
8 years ago
.add();
```
8 years ago
7 years ago
* download
8 years ago
```java
8 years ago
Aria.download(this)
7 years ago
.load(DOWNLOAD_URL) //load download url
.setDownloadPath(DOWNLOAD_PATH) //file save path
.start(); //start download
8 years ago
```
7 years ago
* Pause
8 years ago
```java
8 years ago
Aria.download(this).load(DOWNLOAD_URL).pause();
8 years ago
```
7 years ago
* Resume download
8 years ago
```java
8 years ago
Aria.download(this).load(DOWNLOAD_URL).resume();
```
7 years ago
* Cancel download
8 years ago
```java
8 years ago
Aria.download(this).load(DOWNLOAD_URL).cancel();
```
8 years ago
7 years ago
### downloadStatus
7 years ago
If you want to read the download progress or download the information, then you need to create an event class and register the event class into the Aria manager in the onResume (Activity, Fragment) or constructor (Dialog, PopupWindow).
8 years ago
7 years ago
1. Register the object to Aria
8 years ago
7 years ago
`Aria.download(this).register();` or `Aria.upload(this).register();`
```java
8 years ago
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Aria.download(this).register();
}
```
8 years ago
7 years ago
2. Use`@Download` or `@Upload` to annotate your function<br>
**note:**
- Annotation is done by using `Apt`, so you do not need to worry that this will affect your machine's performance
- The annotated method**can not be modified by private**
- The annotated method**can have only one argument, and the parameter type must be either`DownloadTask` or `UploadTask`**
- Method name can be any string
8 years ago
7 years ago
3. In addition to using annotation methods in widget (Activity, Fragment, Dialog, Popupwindow), you can also use annotation functions in components such as Service, Notification, and so on.
8 years ago
```java
@Download.onPre(DOWNLOAD_URL)
8 years ago
protected void onPre(DownloadTask task) {}
8 years ago
8 years ago
@Download.onTaskStart
void taskStart(DownloadTask task) {}
8 years ago
8 years ago
@Download.onTaskRunning
protected void running(DownloadTask task) {}
8 years ago
8 years ago
@Download.onTaskResume
void taskResume(DownloadTask task) {}
8 years ago
@Download.onTaskStop
void taskStop(DownloadTask task) {}
@Download.onTaskCancel
void taskCancel(DownloadTask task) {}
@Download.onTaskFail
void taskFail(DownloadTask task) {}
@Download.onTaskComplete
void taskComplete(DownloadTask task) {}
8 years ago
8 years ago
@Download.onNoSupportBreakPoint
public void onNoSupportBreakPoint(DownloadTask task) {}
8 years ago
```
7 years ago
4. If you want to set up a listener for a single task, or for some specific task.<br>
**Adding a download address for a task in an annotation means that only the task triggers the annotated method.**
```java
@Download.onTaskRunning({
"https://test.xx.apk",
"http://test.xx2.apk"
}) void taskRunning(DownloadTask task) {
mAdapter.setProgress(task.getDownloadEntity());
}
```
7 years ago
In the above example,only the download address is`https://test.xx.apk` and `http://test.xx2.apk`will trigger the`taskRunning(DownloadTask task)`method。
7 years ago
### parameters
7 years ago
#### [Configuration file setting parameters](https://github.com/AriaLyy/Aria/blob/master/app/src/main/assets/aria_config.xml)
#### Set the parameters in the code
In addition to the file mode to modify the Aria parameter, the same, you can also modify the code in the Aria parameters</br>
Get the configuration file directly through`Aria.get(this).getDownloadConfig()`or`Aria.get(this).getUploadConfig()`</br>
and then modify the parameters:
```java
// 修改最大下载数,调用完成后,立即生效
// 如当前下载任务数是4,修改完成后,当前任务数会被Aria自动调度任务数
Aria.get(this).getDownloadConfig().setMaxTaskNum(3);
```
7 years ago
### interface
7 years ago
* Stop all tasks
```java
Aria.download(this).stopAllTask();
```
7 years ago
* Restore all stopped tasks
```java
Aria.download(this).resumeAllTask();
```
7 years ago
* Delete all tasks
```java
Aria.download(this).removeAllTask();
```
7 years ago
* Maximum download speed limit
8 years ago
```java
//单位为 kb
Aria.download(this).setMaxSpeed(speed);
```
7 years ago
* Get download speed for current tasks<br>
Speed parameters a bit special,need to [download the event support](#下载状态获取)
``` java
@Override public void onTaskRunning(DownloadTask task) {
7 years ago
//If you turn on the speed unit conversion configuration, you can get the download speed with units in the following ways, such as: 1 mb/s
String convertSpeed = task.getConvertSpeed();
7 years ago
//If you have your own unit format, you can get the original byte length by the following method
long speed = task.getSpeed();
}
```
7 years ago
* Get the downloaded file size, the current progress percentage</br>
Likewise, you can also get the downloaded file size in the DownloadTask object
8 years ago
```
@Override public void onTaskRunning(DownloadTask task) {
7 years ago
 //Get the file size
8 years ago
long fileSize = task.getFileSize();
7 years ago
//Get the file size after conversion
String fileSize1 = task.getConvertFileSize();
7 years ago
//The current percentage of progress
int percent = task.getPercent();
8 years ago
}
```
7 years ago
* Set the high priority task<br>
If you want to give priority to download a task, you can
8 years ago
``` java
Aria.download(this).load(DOWNLOAD_URL).setDownloadPath(PATH).setHighestPriority();
```
8 years ago
7 years ago
* Set the extension field<br>
Sometimes, you may want to store some of your own data when you download it</br>
**TIP**: If you have more data, or the data is more complex, you can first convert the data to JSON, and then save it to Aria's download entity
8 years ago
```java
Aria.download(this).load(DOWNLOAD_URL).setExtendField(str)
```
8 years ago
7 years ago
## Upload
* Add a task (add only, do not upload)
8 years ago
```java
Aria.upload(this)
7 years ago
.load(filePath) //file path
.setUploadUrl(uploadUrl) // upload the path
.setAttachment(fileKey) //The server reads the file's key
8 years ago
.add();
```
7 years ago
* Upload
8 years ago
```java
Aria.upload(this)
7 years ago
.load(filePath) //file path
.setUploadUrl(uploadUrl) //upload the path
.setAttachment(fileKey) //The server reads the file's key
8 years ago
.start();
```
7 years ago
* cancel upload
8 years ago
```java
Aria.upload(this).load(filePath).cancel();
8 years ago
```
8 years ago
7 years ago
## Confused configuration
8 years ago
```
-dontwarn com.arialyy.aria.**
-keep class com.arialyy.aria.**{*;}
8 years ago
-keep class **$$DownloadListenerProxy{ *; }
-keep class **$$UploadListenerProxy{ *; }
-keepclasseswithmembernames class * {
@Download.* <methods>;
@Upload.* <methods>;
}
8 years ago
```
8 years ago
7 years ago
## others
Have any questions that can give me a message in the[issues](https://github.com/AriaLyy/Aria/issues)。
8 years ago
***
## 后续版本开发规划
8 years ago
* ~~http、scoket断点上传~~
8 years ago
* ~~实现上传队列调度功能~~
7 years ago
## Development log
+ v_3.1.9 Repair the stopAll queue without task when the problem of collapse, increase the function for a single task monitor
+ v_3.1.7 repair some files can not download the bug, increase the apt annotation method, the incident is more simple
+ v_3.1.6 When the task is canceled ontaskCancel callback twice
+ v_3.1.5 Optimize the code structure, increase the priority download task function.
+ v_3.1.4 Repair the fast switching, pause, and restore functions, the probability of re-download problems, add onPre () callback, onPre () used to request the interface before the implementation of interface UI update operation.
+ v_3.1.0 Add the Aria configuration file to optimize the code
+ v_3.0.3 Repair the pause after deleting the task, flashing the problem, add the api to delete the record
+ v_3.0.2 supports 30x redirect link download
+ v_3.0.0 add upload task support to fix some bugs that have been discovered
9 years ago
License
-------
Copyright 2016 AriaLyy(https://github.com/AriaLyy/Aria)
9 years ago
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
8 years ago
limitations under the License.