### Start Basic HTTP/HTTPS Download in Java Source: https://context7.com/tc999/aria-bak/llms.txt Demonstrates how to initiate a single file download using Aria by providing the download URL and the local file path. Tasks can be created and started immediately or added to a queue for later execution. ```java // Create and start a download task long taskId = Aria.download(this) .load("https://example.com/file.apk") // Download URL .setFilePath("/sdcard/Download/file.apk") // Full file path .create(); // Create and start download // Alternative: Add task without starting (auto-starts when queue available) Aria.download(this) .load("https://example.com/file.zip") .setFilePath("/sdcard/Download/file.zip") .add(); ``` -------------------------------- ### Download with GET Parameters Source: https://github.com/tc999/aria-bak/blob/main/DEV_LOG.md This snippet demonstrates how to initiate a download using the GET method with custom parameters. It requires the Aria library and specifies the download URL, file path, and GET parameters. ```java Aria.download(SingleTaskActivity.this) .load(DOWNLOAD_URL) // url 必须是主体url,也就是?前面的内容 .setFilePath(path, true) .asGet() .setParams(params) // 设置参数 .start(); ``` -------------------------------- ### Create and Manage Group Downloads in Java Source: https://context7.com/tc999/aria-bak/llms.txt This Java example demonstrates how to initiate a group download using the Aria library, which allows downloading multiple files as a single task. It involves creating a list of URLs, loading them into a group download task, specifying a directory for all files, and then starting the download. The code also shows how to control the group download (stop, resume, cancel) using its ID. ```java // Create a download group (e.g., video + subtitles + cover image) List urls = new ArrayList<>(); urls.add("https://example.com/video.mp4"); urls.add("https://example.com/subtitle.srt"); urls.add("https://example.com/cover.jpg"); long groupId = Aria.download(this) .loadGroup(urls) // Load URL list .setDirPath("/sdcard/Download/MovieFolder/") // Folder for all files .create(); // Start download // Control group download by ID Aria.download(this).loadGroup(groupId).stop(); Aria.download(this).loadGroup(groupId).resume(); Aria.download(this).loadGroup(groupId).cancel(); ``` -------------------------------- ### Start Download Task Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md Initiates a download task using the specified download URL and save path. Aria handles the download process, including progress updates and error handling. ```java Aria.download(this) .load(DOWNLOAD_URL) //读取下载地址 .setDownloadPath(DOWNLOAD_PATH) //设置文件保存的完整路径 .start(); //启动下载 ``` -------------------------------- ### Add, Start, and Cancel HTTP Upload Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md Initiate, start, and cancel file uploads using Aria. The load method takes the file path, setUploadUrl specifies the server endpoint, and setAttachment provides a key for the server. ```java Aria.upload(this) .load(filePath) //文件路径 .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(); ``` -------------------------------- ### Manage Aria Upload Tasks in Java Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md This Java code provides examples for managing Aria upload tasks. It covers adding a task without starting the upload, initiating an upload, and canceling an ongoing upload. Key parameters include file path, upload URL, and attachment key. ```java Aria.upload(this) .load(filePath) //文件路径 .setUploadUrl(uploadUrl) //上传路径 .setAttachment(fileKey) //服务器读取文件的key .add(); Aria.upload(this) .load(filePath) //文件路径 .setUploadUrl(uploadUrl) //上传路径 .setAttachment(fileKey) //服务器读取文件的key .start(); Aria.upload(this).load(filePath).cancel(); ``` -------------------------------- ### Initialize and Add Download Task Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md Demonstrates how to initialize Aria and add a download task without immediately starting it. The task will automatically begin when other downloads complete. Requires specifying the download URL and the local save path. ```java Aria.download(this) .load(DOWNLOAD_URL) .setDownloadPath(DOWNLOAD_PATH) //文件保存路径 .add(); ``` -------------------------------- ### Download with POST Parameters Source: https://github.com/tc999/aria-bak/blob/main/DEV_LOG.md This code example shows how to perform a download using the POST method, including setting key-value pairs as parameters. It utilizes the Aria download API and specifies the URL, file path, and POST parameters. ```java Aria.download(SingleTaskActivity.this) .load(DOWNLOAD_URL) .setFilePath(path) .asPost() // post请求 .setParam("key", "value") //传递参数 //.setParams(Map) // 传递多参数 .start(); ``` -------------------------------- ### Handle Download Events with Annotations Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md Utilizes Apt annotations to handle various download events. These methods must not be private and should accept a single DownloadTask parameter. Examples include onPre, onTaskStart, onTaskRunning, etc. ```java @Download.onPre(DOWNLOAD_URL) protected void onPre(DownloadTask task) {} @Download.onTaskStart void taskStart(DownloadTask task) {} @Download.onTaskRunning protected void running(DownloadTask task) {} @Download.onTaskResume void taskResume(DownloadTask task) {} @Download.onTaskStop void taskStop(DownloadTask task) {} @Download.onTaskCancel void taskCancel(DownloadTask task) {} @Download.onTaskFail void taskFail(DownloadTask task) {} @Download.onTaskComplete void taskComplete(DownloadTask task) {} @Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) {} ``` -------------------------------- ### Start a Download Task in Android Source: https://github.com/tc999/aria-bak/blob/main/README.md This Java code demonstrates how to initiate a single file download using Aria. It involves loading the download URL, specifying the file save path, and then calling `create()` to start the download process. The method returns a taskId which can be used to manage the task later. ```java long taskId = Aria.download(this) .load(DOWNLOAD_URL) // Read download address .setFilePath(DOWNLOAD_PATH) // Set the complete save path of the file .create(); // Create and start the download ``` -------------------------------- ### Start, Pause, and Cancel HTTP Downloads Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md Demonstrates how to initiate, pause, and cancel a single file download using Aria's download API. The load method takes the download URL, and setDownloadPath specifies the save location. ```java Aria.download(this) .load(DOWNLOAD_URL) //读取下载地址 .setDownloadPath(DOWNLOAD_PATH) //设置文件保存的完整路径 .start(); //启动下载 ``` ```java Aria.download(this).load(DOWNLOAD_URL).pause(); ``` ```java Aria.download(this).load(DOWNLOAD_URL).cancel(); ``` -------------------------------- ### Get Download Speed and File Info in Java Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md This Java code shows how to retrieve download speed and file information within the `onTaskRunning` callback in Aria. It illustrates how to get the formatted speed (e.g., '1 mb/s') using `getConvertSpeed()` or the raw byte speed using `getSpeed()`. It also covers fetching file size and conversion, along with the download percentage. ```java @Override public void onTaskRunning(DownloadTask task) { //如果你打开了速度单位转换配置,将可以通过以下方法获取带单位的下载速度,如:1 mb/s String convertSpeed = task.getConvertSpeed(); //如果你有自己的单位格式,可以通过以下方法获取原始byte长度 long speed = task.getSpeed(); //获取文件大小 long fileSize = task.getFileSize(); //获取单位转换后的文件大小 String fileSize1 = task.getConvertFileSize(); //当前进度百分比 int percent = task.getPercent(); } ``` -------------------------------- ### Start, Pause, and Cancel FTP Single File Upload Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md Upload single files to an FTP server. Specify the local file path, FTP server address, login credentials, and start the upload process. Resuming and canceling uploads are also supported. ```java Aria.upload(this) .loadFtp("/mnt/sdcard/gggg.apk") //上传文件路径 .setUploadUrl(URL) //上传的ftp服务器地址 .login("lao", "123456") .start(); ``` ```java Aria.upload(this).loadFtp(FILE_PATH).stop(); ``` ```java Aria.upload(this).loadFtp(FILE_PATH).cancel(); ``` -------------------------------- ### Monitor Download Progress with Annotations in Java Source: https://context7.com/tc999/aria-bak/llms.txt This Java code demonstrates how to monitor download progress within an Android Activity using the Aria library. It registers for download events, starts a download, and provides callback methods for various stages like pre-processing, task start, running, completion, failure, stop, cancellation, and handling unsupported breakpoint resumability. It utilizes annotations like @Download.onPre, @Download.onTaskRunning, etc. ```java public class DownloadActivity extends AppCompatActivity { private static final String DOWNLOAD_URL = "https://example.com/largefile.zip"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_download); // Register this activity to receive download events Aria.download(this).register(); // Start download Aria.download(this) .load(DOWNLOAD_URL) .setFilePath("/sdcard/Download/largefile.zip") .create(); } @Override protected void onDestroy() { super.onDestroy(); Aria.download(this).unRegister(); } // Pre-processing callback before download starts @Download.onPre protected void onPre(DownloadTask task) { // Update UI before download begins Log.d("Aria", "Preparing to download: " + task.getFileName()); } // Callback when new task starts @Download.onTaskStart void onTaskStart(DownloadTask task) { Log.d("Aria", "Download started: " + task.getFileName()); } // Callback for download progress updates @Download.onTaskRunning protected void onTaskRunning(DownloadTask task) { int percent = task.getPercent(); // Progress percentage String speed = task.getConvertSpeed(); // Formatted speed (e.g., "1.5 MB/s") long rawSpeed = task.getSpeed(); // Raw speed in bytes/s long fileSize = task.getFileSize(); // Total file size long currentProgress = task.getCurrentProgress(); // Downloaded bytes // Update progress bar progressBar.setProgress(percent); speedTextView.setText(speed); } // Callback when download completes successfully @Download.onTaskComplete void onTaskComplete(DownloadTask task) { Log.d("Aria", "Download completed: " + task.getFilePath()); Toast.makeText(this, "Download finished!", Toast.LENGTH_SHORT).show(); } // Callback when download fails @Download.onTaskFail void onTaskFail(DownloadTask task) { Log.e("Aria", "Download failed: " + task.getFileName()); Toast.makeText(this, "Download error!", Toast.LENGTH_SHORT).show(); } // Callback when task is stopped @Download.onTaskStop void onTaskStop(DownloadTask task) { Log.d("Aria", "Download stopped: " + task.getFileName()); } // Callback when task is cancelled @Download.onTaskCancel void onTaskCancel(DownloadTask task) { Log.d("Aria", "Download cancelled: " + task.getFileName()); } // Handle servers that don't support resumable downloads @Download.onNoSupportBreakPoint void onNoSupportBreakPoint(DownloadTask task) { Log.w("Aria", "Server doesn't support resume: " + task.getUrl()); } } ``` -------------------------------- ### Start, Pause, and Cancel FTP Folder Download Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md Download entire folders from an FTP server. Specify the FTP directory URL, local download path, and login credentials. Aria handles downloading all files within the specified directory. ```java Aria.download(this) .loadFtpDir("ftp://172.18.104.129:21/haha/") .setDownloadDirPath(downloadPath) .login("lao", "123456") .start(); ``` ```java Aria.download(this).loadFtpDir(dir).stop(); ``` ```java Aria.download(this).loadFtpDir(dir).cancel(); ``` -------------------------------- ### Start, Pause, and Cancel HTTP Download Group Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md Manage downloads for a group of files. The setDownloadDirPath is used to specify the directory for all files in the group. Individual save paths are not required for each file. ```java Aria.download(this) .load(urls) //设置一主任务,参数为List .setDownloadDirPath(groupDirPath) //设置任务组的文件夹路径 .start(); //启动下载 ``` ```java Aria.download(this).load(urls).pause(); ``` ```java Aria.download(this).load(urls).cancel(); ``` -------------------------------- ### Control Aria Download Tasks in Java Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md Provides Java code examples for common download task management operations in Aria. This includes stopping all ongoing downloads, resuming all paused tasks, removing all tasks from the queue, and setting a maximum download speed limit. ```java // 停止所有任务 Aria.download(this).stopAllTask(); // 恢复所有停止的任务 Aria.download(this).resumeAllTask(); // 删除所有任务 Aria.download(this).removeAllTask(); // 最大下载速度限制 //单位为 kb Aria.download(this).setMaxSpeed(speed); ``` -------------------------------- ### Start, Pause, and Cancel FTP Single File Download Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md Perform FTP single file downloads, including resuming interrupted downloads. Requires specifying the FTP URL, login credentials, and the local download path. ```java Aria.download(this) .loadFtp("ftp://172.18.104.129:21/haha/large.rar") .login("lao", "123456") //登录FTP服务器 .setDownloadPath("/mnt/sdcard/") //设置文件保存文件夹 .start(); ``` ```java Aria.download(this).loadFtp(URL).stop(); ``` ```java Aria.download(this).loadFtp(URL).cancel(); ``` -------------------------------- ### Handle Download Task Failure with Exception Source: https://github.com/tc999/aria-bak/blob/main/DEV_LOG.md This example demonstrates how to handle download task failures by providing a callback method that receives the task and an Exception object. It shows how to access the error message from the exception. ```java @Download.onTaskFail void taskFail(DownloadTask task, Exception e) { e.getMessage(); ... } ``` -------------------------------- ### Query Download Task Information Source: https://context7.com/tc999/aria-bak/llms.txt Retrieve lists of all, running, or specific download tasks. You can also check if a URL is currently downloading or get detailed information about a specific task. ```java // Get all download tasks List allTasks = Aria.download(this).getTaskList(); // Get running tasks only List runningTasks = Aria.download(this).getRunningTask(); // Check if specific URL is downloading boolean isDownloading = Aria.download(this) .load("https://example.com/file.zip") .isRunning(); // Get task details DownloadEntity entity = Aria.download(this).getDownloadEntity(taskId); if (entity != null) { String fileName = entity.getFileName(); long fileSize = entity.getFileSize(); int state = entity.getState(); long downloadedSize = entity.getCurrentProgress(); } ``` -------------------------------- ### Task Status Retrieval Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md This section details how to retrieve task progress and information by registering event listeners with the Aria manager. It covers the annotation-based approach for handling various task states like pre-processing, start, resume, running, stop, cancellation, failure, completion, and unsupported breakpoint scenarios. ```APIDOC ## Task Status Retrieval To read task progress or task information, you need to create an event class and register it with the Aria manager in `onResume(Activity, Fragment)` or the constructor (Dialog, PopupWindow). 1. **Register the object with Aria** ```java Aria.download(this).register(); // or Aria.upload(this).register(); ``` Example in `onCreate`: ```java @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Aria.download(this).register(); } ``` 2. **Use `@Download`, `@Upload`, or `@DownloadGroup` annotations for your methods** **Notes:** - Annotated callbacks are implemented using Apt, so they don't affect machine performance. - Annotated methods **cannot be private**. - Annotated methods **must have exactly one parameter**, and the parameter type must be `DownloadTask`, `UploadTask`, or `DownloadGroupTask`. - Method names can be any string. 3. **Annotated methods can be used in Services, Notifications, etc., in addition to widgets (Activity, Fragment, Dialog, PopupWindow).** | Annotation | Description | | ------------------------- | --------------------------------------------------------------------------- | | `@Download.onPre` | Pre-processing annotation, called before the task starts (usually for UI preprocessing). | | `@Download.onTaskStart` | Annotation for task start, called when a new task begins. | | `@Download.onTaskResume` | Annotation for task resume, called before a stopped task resumes operation. | | `@Download.onTaskRunning` | Annotation for task running, called while the task is executing. | | `@Download.onTaskStop` | Annotation for task stop, called when the task stops. | | `@Download.onTaskCancel` | Annotation for task cancellation, called when the task is deleted. | | `@Download.onTaskFail` | Annotation for task failure, called when the task execution fails. | | `@Download.onTaskComplete`| Annotation for task completion, called when the task finishes. | | `@Download.onNoSupportBreakPoint` | Special annotation for handling tasks that do not support breakpoint resumes. | **Example:** ```java @Download.onPre void onPre(DownloadTask task) {} @Download.onTaskStart void taskStart(DownloadTask task) {} @Download.onTaskResume void taskResume(DownloadTask task) {} @Download.onTaskRunning void running(DownloadTask task) {} @Download.onTaskStop void taskStop(DownloadTask task) {} @Download.onTaskCancel void taskCancel(DownloadTask task) {} @Download.onTaskFail void taskFail(DownloadTask task) {} @Download.onTaskComplete void taskComplete(DownloadTask task) {} @Download.onNoSupportBreakPoint void onNoSupportBreakPoint(DownloadTask task) {} ``` **TIP:** If you only want to set a listener for a single task or specific tasks, add the download URL in the annotation. This will trigger the annotated method only for that specific task. ```java @Download.onTaskRunning({ "https://test.xx.apk", "http://test.xx2.apk" }) void taskRunning(DownloadTask task) { mAdapter.setProgress(task.getDownloadEntity()); } ``` In the example above, the `taskRunning(DownloadTask task)` method will only be triggered if the download URL is `https://test.xx.apk` or `http://test.xx2.apk`. ``` -------------------------------- ### Getting Download Speed and File Size in Java Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md This Java code within an `onTaskRunning` callback demonstrates how to retrieve the current download speed and file size. It provides methods for both raw byte values and human-readable converted strings, assuming speed unit conversion is enabled in Aria's configuration. ```java import com.arialyy.aria.core.download.DownloadTask; @Override public void onTaskRunning(DownloadTask task) { // Get download speed with unit conversion (e.g., "1 mb/s") String convertSpeed = task.getConvertSpeed(); // Get raw download speed in bytes per second long speed = task.getSpeed(); // Get file size with unit conversion (e.g., "100 MB") String fileSize1 = task.getConvertFileSize(); // Get raw file size in bytes long fileSize = task.getFileSize(); // Get current progress percentage int percent = task.getPercent(); } ``` -------------------------------- ### Setting and Getting Extend Field for Aria Downloads in Java Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md This Java code shows how to attach custom data (extend field) to an Aria download task and retrieve it later. This is useful for storing metadata associated with the download. The data can be a String, and complex data should be converted to JSON. ```java import com.arialyy.aria.core.Aria; String DOWNLOAD_URL = "some_download_url"; String EXTEND_DATA = "your_custom_data_or_json_string"; // Set the extend field for a download task Aria.download(this).load(DOWNLOAD_URL) .setExtendField(EXTEND_DATA); // Get the extend field for a download task String retrievedData = Aria.download(this).load(DOWNLOAD_URL) .getExtendField(); ``` -------------------------------- ### Aria: Create, Stop, and Resume Download Tasks Source: https://github.com/tc999/aria-bak/blob/main/ENGLISH_README.md Demonstrates the basic usage of Aria for managing download tasks. This includes creating a new download task with a URL and file path, and methods to stop or resume an existing task using its ID. ```java long taskId = Aria.download(this) .load(DOWNLOAD_URL) //Read download address .setFilePath(DOWNLOAD_PATH) //Set the full path where the file is saved .create(); //Create and start download ``` ```java Aria.download(this) .load(taskId) //task id .stop(); // stop task //.resume(); // resume task ``` -------------------------------- ### Configuration File Settings (`aria_config.xml`) Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md This section details the parameters that can be configured in the `aria_config.xml` file to customize download behavior. ```APIDOC ## Configuration File Settings (`aria_config.xml`) ### Description This section details the parameters that can be configured in the `aria_config.xml` file to customize download behavior. The `aria_config.xml` file should be placed in the `assets` directory. ### Parameters #### Download Configuration - **threadNum** (integer) - Sets the number of download threads. Changes take effect for new download tasks. - **openBroadcast** (boolean) - Enables or disables download broadcast (defaults to `false`). Using `Download` annotations for callbacks is recommended. - **maxTaskNum** (integer) - Sets the maximum number of concurrent download tasks (defaults to `2`). - **reTryNum** (integer) - Specifies the number of retry attempts for failed downloads (defaults to `10`). - **reTryInterval** (integer) - Sets the interval between retries in milliseconds (defaults to `2000` ms). - **connectTimeOut** (integer) - Sets the connection timeout for URLs in milliseconds (defaults to `5000` ms). - **iOTimeOut** (integer) - Sets the IO stream read timeout in milliseconds (defaults to `20000` ms). This value cannot be less than `10000` ms. - **buffSize** (integer) - Sets the buffer size for writing files. This value cannot be less than `2048`. Smaller values may decrease download speed. - **ca** (object) - Configures HTTPS CA certificate information. Requires `path` (full path to CA certificate in `assets`) and `name` (CA certificate name). - **convertSpeed** (boolean) - Determines whether to convert speed units (e.g., `1b/s`, `1kb/s`, `1mb/s`). If `false`, speed is returned in bytes. - **maxSpeed** (integer) - Sets the maximum download speed in kbps. `0` indicates unlimited speed. #### Upload Configuration - **openBroadcast** (boolean) - Enables or disables upload broadcast (defaults to `false`). - **maxTaskNum** (integer) - Sets the maximum number of concurrent upload tasks (defaults to `2`). - **reTryNum** (integer) - Specifies the number of retry attempts for failed uploads (defaults to `10`). - **reTryInterval** (integer) - Sets the interval between retries in milliseconds (defaults to `2000` ms). - **connectTimeOut** (integer) - Sets the connection timeout for URLs in milliseconds (defaults to `5000` ms). ### Example `aria_config.xml` ```xml ``` ``` -------------------------------- ### Proguard/Obfuscation Configuration Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md Recommended Proguard rules to ensure Aria functions correctly after code obfuscation. ```APIDOC ## Proguard/Obfuscation Configuration ### Description To ensure Aria works correctly after your application is obfuscated using Proguard or R8, include the following rules in your `proguard-rules.pro` file. ### Rules ``` -dontwarn com.arialyy.aria.* -keep class com.arialyy.aria.** {*;} -keep class **$$DownloadListenerProxy { *; } -keep class **$$UploadListenerProxy { *; } -keep class **$$DownloadGroupSubListenerProxy{*;} -keepclasseswithmembernames class * { @com.arialyy.aria.core.download.DownloadTarget ; @com.arialyy.aria.core.upload.UploadTarget ; } ``` ``` -------------------------------- ### Add Aria Dependencies Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md Include the Aria core library and compiler annotation processor in your project's build.gradle file to enable download and upload functionalities. ```gradle compile 'com.arialyy.aria:aria-core:3.2.20' annotationProcessor 'com.arialyy.aria:aria-compiler:3.2.20' ``` -------------------------------- ### Aria Parameter Configuration Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md This section describes how to configure Aria parameters, either through a configuration file in the `assets` directory or dynamically within your code. ```APIDOC ## Aria Parameter Configuration ### Configuration File Settings Create an `aria_config.xml` file and place it in the `assets` directory. ### Code Settings In addition to modifying Aria parameters via files, you can also dynamically change them in your code. You can obtain the configuration file directly using `Aria.get(this).getDownloadConfig()` or `Aria.get(this).getUploadConfig()`, and then modify the parameters. Example: ```java // Modify the maximum number of download tasks. Takes effect immediately after the call. // If the current number of download tasks is 4, after modification, Aria will automatically schedule the tasks to match the new limit. Aria.get(this).getDownloadConfig().setMaxTaskNum(3); ``` ``` -------------------------------- ### Upload API Methods Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md API methods for initiating, managing, and canceling upload tasks. ```APIDOC ## Upload API Methods ### Description This section details the API methods available for handling file uploads. ### API Methods - **add()**: Adds an upload task to the queue without starting the upload immediately. ```java Aria.upload(this) .load(filePath) // File path .setUploadUrl(uploadUrl) // Upload URL .setAttachment(fileKey) // Key for the server to read the file .add(); ``` - **start()**: Initiates an upload task. ```java Aria.upload(this) .load(filePath) // File path .setUploadUrl(uploadUrl) // Upload URL .setAttachment(fileKey) // Key for the server to read the file .start(); ``` - **cancel()**: Cancels an ongoing upload task. ```java Aria.upload(this).load(filePath).cancel(); ``` ``` -------------------------------- ### Common Download API Methods Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md Essential methods for managing download tasks, including stopping, resuming, deleting, and setting download priorities and limits. ```APIDOC ## Common Download API Methods ### Description This section covers frequently used API methods for controlling and monitoring download tasks. ### API Methods - **stopAllTask()**: Stops all ongoing download tasks. ```java Aria.download(this).stopAllTask(); ``` - **resumeAllTask()**: Resumes all previously stopped download tasks. ```java Aria.download(this).resumeAllTask(); ``` - **removeAllTask()**: Deletes all download tasks (both completed and pending). ```java Aria.download(this).removeAllTask(); ``` - **setMaxSpeed(long speed)**: Sets the maximum download speed limit in kbps. ```java // speed is in kbps Aria.download(this).setMaxSpeed(speed); ``` - **setHighestPriority()**: Assigns the highest priority to a download task, ensuring it gets processed first. ```java Aria.download(this).load(DOWNLOAD_URL).setDownloadPath(PATH).setHighestPriority(); ``` - **setExtendField(String data)**: Attaches custom data to a download task. This data can be retrieved later. For complex data, consider converting it to JSON. ```java Aria.download(this).load(DOWNLOAD_URL).setExtendField(str); ``` ### Task Information Retrieval (within `onTaskRunning` callback) - **getConvertSpeed()**: Returns the download speed formatted with units (e.g., "1 mb/s"). Requires `convertSpeed` to be enabled in configuration. - **getSpeed()**: Returns the raw download speed in bytes per second. - **getFileSize()**: Returns the total file size in bytes. - **getConvertFileSize()**: Returns the file size formatted with units. - **getPercent()**: Returns the current download progress as a percentage (0-100). ``` -------------------------------- ### Add Aria Core and Components (Gradle) Source: https://github.com/tc999/aria-bak/blob/main/ENGLISH_README.md These are Gradle dependencies required to integrate the Aria download framework into an Android project. The core module provides basic download functionality, while additional components like ftpComponent, sftpComponent, and m3u8Component enable support for specific protocols and features. The annotationProcessor is necessary for code generation. ```gradle implementation 'com.arialyy.aria:core:3.8.10' annotationProcessor 'com.arialyy.aria:compiler:3.8.10' implementation 'com.arialyy.aria:ftpComponent:3.8.10' // If you need to use ftp, please add this component implementation 'com.arialyy.aria:sftpComponent:3.8.10' // If you need to use sftp, please add this component implementation 'com.arialyy.aria:m3u8Component:3.8.10' // If you need to use the m3u8 download function, please add this component ``` -------------------------------- ### Aria: ProGuard Configuration for Release Builds Source: https://github.com/tc999/aria-bak/blob/main/ENGLISH_README.md Provides the necessary ProGuard rules for the Aria library. These rules ensure that the library's code is correctly processed and preserved during code shrinking and obfuscation for release builds. ```proguard -dontwarn com.arialyy.aria.** -keep class com.arialyy.aria.**{*;} -keep class **$$DownloadListenerProxy{ *; } -keep class **$$UploadListenerProxy{ *; } -keep class **$$DownloadGroupListenerProxy{ *; } -keep class **$$DGSubListenerProxy{ *; } -keepclasseswithmembernames class * { @Download.* ; @Upload.* ; @DownloadGroup.* ; } ``` -------------------------------- ### Configure Aria Download Settings via XML Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md This XML configuration file allows setting various parameters for the Aria download manager, such as thread count, retry attempts, timeouts, buffer size, and speed limits. Modifications made here override code-based settings and take effect for new download tasks. ```xml ``` -------------------------------- ### Register for Download Task Status Callbacks Source: https://github.com/tc999/aria-bak/blob/main/README.md To receive updates on download task progress and completion, you need to register your Activity or Fragment with Aria. This is typically done in the `onCreate()` method. Aria uses annotations to handle the callbacks, providing a clean separation of concerns. ```java protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Aria.download(this).register(); } ``` -------------------------------- ### Programmatic Parameter Configuration Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md Demonstrates how to dynamically modify Aria parameters directly within your code, overriding XML configurations. ```APIDOC ## Programmatic Parameter Configuration ### Description Besides configuring Aria parameters via the `aria_config.xml` file, you can also dynamically modify them in your code. This allows for runtime adjustments that take immediate effect. ### Method Access the configuration objects using `Aria.get(this).getDownloadConfig()` or `Aria.get(this).getUploadConfig()` and then call the respective setter methods. ### Example ```java // Modify the maximum number of download tasks. The change takes effect immediately. // If the current number of download tasks is 4, Aria will automatically schedule tasks after the change. Aria.get(this).getDownloadConfig().setMaxTaskNum(3); ``` ``` -------------------------------- ### Aria: Handling Task Status with Annotations (Java) Source: https://github.com/tc999/aria-bak/blob/main/ENGLISH_README.md Illustrates how to use annotations to process download task events like running and completion. Annotated methods must not be private and can only accept a single parameter of type DownloadTask, UploadTask, or DownloadGroupTask. ```java //Process the status of the task execution here, such as the refresh of the progress bar @Download.onTaskRunning protected void running(DownloadTask task) { if(task.getKey().eques(url)){ .... You can judge whether it is the callback of the specified task by url } int p = task.getPercent(); //Task progress percentage String speed = task.getConvertSpeed(); //Download speed after unit conversion, unit conversion needs to be opened in the configuration file String speed1 = task.getSpeed(); //Original byte length speed } ``` ```java @Download.onTaskComplete void taskComplete(DownloadTask task) { //Process the status of task completion here } ``` -------------------------------- ### Add Aria Dependencies Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md Include the Aria library and its compiler as dependencies in your project's build.gradle file. This is necessary to leverage Aria's download and upload functionalities. ```java compile 'com.arialyy.aria:Aria:3.1.9' annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.9' ``` -------------------------------- ### Handling Download Task Events with Annotations in Java Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md This Java code illustrates how to use Aria annotations to handle various download task events. Methods annotated with `@Download.onPre`, `@Download.onTaskStart`, `@Download.onTaskRunning`, etc., will be automatically invoked when the corresponding event occurs. These methods must not be private and should accept a single parameter of type `DownloadTask`, `UploadTask`, or `DownloadGroupTask`. ```java import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DownloadGroupTask; import com.arialyy.aria.core.download.AriaDownload; // Example of handling different download events @Download.onPre void onPre(DownloadTask task) { // Pre-processing before the task starts, e.g., UI updates } @Download.onTaskStart void taskStart(DownloadTask task) { // Callback when a new task starts } @Download.onTaskRunning void running(DownloadTask task) { // Callback when the task is actively running String convertSpeed = task.getConvertSpeed(); // Get converted speed long speed = task.getSpeed(); // Get raw speed in bytes long fileSize = task.getFileSize(); // Get file size String fileSize1 = task.getConvertFileSize(); // Get converted file size int percent = task.getPercent(); // Get current progress percentage } @Download.onTaskStop void taskStop(DownloadTask task) { // Callback when the task is stopped } @Download.onTaskCancel void taskCancel(DownloadTask task) { // Callback when the task is canceled } @Download.onTaskFail void taskFail(DownloadTask task) { // Callback when the task fails } @Download.onTaskComplete void taskComplete(DownloadTask task) { // Callback when the task completes successfully } @Download.onNoSupportBreakPoint void onNoSupportBreakPoint(DownloadTask task) { // Callback for tasks that do not support breakpoint resuming } ``` -------------------------------- ### Common API Interfaces Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md Provides a list of frequently used API methods for managing download and upload tasks, including stopping, resuming, removing tasks, setting speed limits, and managing task priority. ```APIDOC ## Common API Interfaces | API | Description ``` -------------------------------- ### Proguard Configuration for Aria Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md This Proguard configuration is essential for shrinking and obfuscating Java code when using the Aria library. It includes rules to prevent warnings and ensure necessary classes and members are kept, particularly those related to download and upload listener proxies and annotations. ```proguard -dontwarn com.arialyy.aria.* -keep class com.arialyy.aria.**{*;} -keep class **$$DownloadListenerProxy{ *; } -keep class **$$UploadListenerProxy{ *; } -keep class **$$DownloadGroupSubListenerProxy{*;} -keepclasseswithmembernames class * { @Download.* ; @Upload.* ; } ``` -------------------------------- ### Resume Download Task Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md Resumes a previously paused download task. Aria will attempt to continue the download from where it left off. ```java Aria.download(this).load(DOWNLOAD_URL).resume(); ``` -------------------------------- ### ProGuard Configuration for Aria Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md This snippet provides the necessary ProGuard rules to ensure the Aria library functions correctly after code obfuscation. It includes rules to prevent warnings and keep necessary classes and members, particularly those related to Aria's annotation processing and listener proxies. ```proguard -dontwarn com.arialyy.aria.** -keep class com.arialyy.aria.** {*;} -keep class **$$DownloadListenerProxy { *; } -keep class **$$UploadListenerProxy { *; } -keep class **$$DownloadGroupListenerProxy { *; } -keepclasseswithmembernames class * { @Download.* ; @Upload.* ; @DownloadGroup.* ; } ``` -------------------------------- ### Register Download Listener Source: https://github.com/tc999/aria-bak/blob/main/CHINESE_README.md Registers the current context (e.g., Activity, Fragment) with Aria to receive download status updates. This must be done before using @Download annotations. ```java @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Aria.download(this).register(); } ``` -------------------------------- ### Resuming All Stopped Aria Download Tasks in Java Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md This Java code shows how to resume all Aria download tasks that have been previously stopped. Executing `Aria.download(this).resumeAllTask()` will restart all pending downloads. ```java import com.arialyy.aria.core.Aria; // Resume all stopped download tasks Aria.download(this).resumeAllTask(); ``` -------------------------------- ### Configure HTTPS CA Certificate in Aria Source: https://github.com/tc999/aria-bak/blob/main/DownloadApi.md Sets the CA certificate information for secure HTTPS connections. The certificate file should be placed in the assets directory, and its alias and path are required. ```java /** * 设置CA证书信息 * * @param caAlias ca证书别名 * @param caPath assets 文件夹下的ca证书完整路径 */ Aria.get(this).setCAInfo("caAlias","caPath"); ``` -------------------------------- ### Handle Download Task Status with Annotations Source: https://github.com/tc999/aria-bak/blob/main/README.md Aria utilizes annotations for handling download task states. You can use annotations like `@Download.onTaskRunning`, `@Download.onTaskComplete`, etc., to define methods that will be automatically called when the corresponding task events occur. These methods can receive a `DownloadTask` object for details like progress and speed. ```java // Handle task execution status, such as refreshing the progress bar @Download.onTaskRunning protected void running(DownloadTask task) { if(task.getKey().eques(url)){ .... // You can determine if it's the specified task's callback by url } int p = task.getPercent(); // Task progress percentage String speed = task.getConvertSpeed(); // Download speed after unit conversion, unit conversion needs to be enabled in the configuration file String speed1 = task.getSpeed(); // Original byte length speed } @Download.onTaskComplete void taskComplete(DownloadTask task) { // Handle task completion status here } ``` -------------------------------- ### Setting Max Speed for Aria Downloads in Java Source: https://github.com/tc999/aria-bak/blob/main/MORE_API.md This Java code demonstrates how to limit the maximum download speed for a specific task using Aria. The `setMaxSpeed` method takes the speed limit in kb/s as an argument. ```java import com.arialyy.aria.core.Aria; // Set the maximum download speed to 1000 kb/s Aria.download(this).setMaxSpeed(1000); ``` -------------------------------- ### Add Aria Dependencies to Gradle Project Source: https://context7.com/tc999/aria-bak/llms.txt Integrates the Aria framework and its optional modules (FTP, SFTP, M3U8) into your Android project by adding dependencies to the app's build.gradle file. ```gradle repositories { google() mavenCentral() } dependencies { implementation 'me.laoyuyu.aria:core:3.8.16' annotationProcessor 'me.laoyuyu.aria:compiler:3.8.16' implementation 'me.laoyuyu.aria:ftp:3.8.16' // Optional: for FTP support implementation 'me.laoyuyu.aria:sftp:3.8.16' // Optional: for SFTP support implementation 'me.laoyuyu.aria:m3u8:3.8.16' // Optional: for M3U8 download } ``` -------------------------------- ### Monitor Upload Progress with Aria Callbacks Source: https://context7.com/tc999/aria-bak/llms.txt Provides callback methods to monitor the progress and status of HTTP/HTTPS uploads. Requires registering the upload listener and implementing methods for running, complete, and failed tasks to update UI elements like progress bars and status messages. ```java @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Aria.upload(this).register(); } @Upload.onTaskRunning protected void onUploadRunning(UploadTask task) { int percent = task.getPercent(); String speed = task.getConvertSpeed(); long currentProgress = task.getCurrentProgress(); uploadProgressBar.setProgress(percent); uploadSpeedText.setText(speed); } @Upload.onTaskComplete void onUploadComplete(UploadTask task) { Log.d("Aria", "Upload successful: " + task.getFilePath()); } @Upload.onTaskFail void onUploadFail(UploadTask task) { Log.e("Aria", "Upload failed: " + task.getFilePath()); } ```