鸿蒙开源组件——文件下载库

jacksky
发布于 2021-10-15 17:50
浏览
0收藏

PRDownloader

项目介绍

  • 项目名称:PRDownloader
  • 所属系列:openharmony第三方组件适配移植
  • 功能:一个文件下载库的openharmony与暂停和恢复支持
  • 项目移植状态:主功能完成
  • 调用差异:无
  • 开发版本:sdk6,DevEco Studio2.2 beta1
  • 基线版本:Release 0.6.0

效果演示鸿蒙开源组件——文件下载库-鸿蒙开发者社区

安装教程

在moudle级别下的build.gradle文件中添加依赖

// 添加maven仓库
repositories {
   maven {
       url 'https://s01.oss.sonatype.org/content/repositories/releases/'
   }
}

// 添加依赖库
dependencies {
   implementation 'com.gitee.chinasoft_ohos:prdownloader:1.0.0'
}

在sdk6,DevEco Studio2.2 beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下

使用说明

一个文件下载库的openharmony与暂停和恢复支持

Add this in your build.gradle

implementation 'com.gitee.chinasoft_ohos:prdownloader:1.0.0'

如果已经不存在,不要忘记在config.json中添加互联网许可

 "deviceConfig": {
    "default": {
      "network": {
        "usesCleartext": true
      }
    }
  }

然后在应用程序类的onStart()方法中初始化它:

PRDownloader.initialize(getApplicationContext());
  • 发送一个下载请求
    int downloadId = PRDownloader.download(url, dirPath, fileName)
                            .build()
                            .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                                @Override
                                public void onStartOrResume() {
                                   
                                }
                            })
                            .setOnPauseListener(new OnPauseListener() {
                                @Override
                                public void onPause() {
                                   
                                }
                            })
                            .setOnCancelListener(new OnCancelListener() {
                                @Override
                                public void onCancel() {
                                    
                                }
                            })
                            .setOnProgressListener(new OnProgressListener() {
                                @Override
                                public void onProgress(Progress progress) {
                                   
                                }
                            })
                            .start(new OnDownloadListener() {
                                @Override
                                public void onDownloadComplete() {
                                   
                                }
    
                                @Override
                                public void onError(Error error) {
                                   
                                }
                            });            ​
  • 暂停一个下载请求
    PRDownloader.pause(downloadId);​
  • 重新继续一个下载请求
    PRDownloader.resume(downloadId);​
  • 退出一个下载请求
    // Cancel with the download id
    PRDownloader.cancel(downloadId);
    // The tag can be set to any request and then can be used to cancel the request
    PRDownloader.cancel(TAG);
    // Cancel all the requests
    PRDownloader.cancelAll();​
  • 下载状态获取
    Status status = PRDownloader.getStatus(downloadId);​
  • 如果启用了数据库,清理恢复的文件
    // Method to clean up temporary resumed files which is older than the given day
    PRDownloader.cleanUp(days);​
  • TODO *与其他库如OkHttp, RxJava集成 *测试用例 *当然还有许多功能和bug修复

测试信息

CodeCheck代码测试无异常

CloudTest代码测试无异常

病毒安全检测通过

当前版本demo功能与原组件基本无差异

版本迭代

  • 1.0.0

版权和许可信息

   Copyright (C) 2017 MINDORKS NEXTGEN PRIVATE LIMITED

   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
   limitations under the License.

 

PRDownloader-master.zip 535.58K 48次下载
已于2021-10-15 17:50:09修改
收藏
回复
举报
回复
    相关推荐