Git Product home page Git Product logo

upgrade's Introduction

Upgrade

Android 版本升级

  • 支持断点续传;
  • 支持下载速度计算;
  • 仅可同时下载一个文件(防止重复下载);
  • 支持检测网络状态,网络重连后自动继续下载;

Screenshot

使用

  • 方式 1
  • 方式 2. 拷贝Libs工程里面的lib_upgrade到自己的工程里面

注意点

下载是通过开启IntentService在后台下载,任务完成后自动停止;

范例

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    mBtnStartDownload.setOnClickListener {
        startUpdate()
    }

    register()
    //register2()
}

private fun startUpdate() {
    // 开启下载,下载会在IntentService中执行,如果当前正在下载中,不会重复执行下载任务
    DownloadManager.downloadApk(
        this, "https://XXX/YYY.apk"
    )
}

@SuppressLint("SetTextI18n")
private fun register() {
    DownloadManager.registerWithAutoInstall(this) { progress, speed ->
        mTvProgress.text = "${progress}%"
        mTvSpeed.text = speed
    }
}

// or auto manual install
@SuppressLint("SetTextI18n")
private fun register2() {
    DownloadManager.register(this, { progress, speed ->
        mTvProgress.text = "${progress}%"
        mTvSpeed.text = speed
    }, { fileName ->
        // there is a dialog in install method,if we register context is not activity,
        // we must manual install by this method.
        DownloadManager.installWithPermission(this, fileName)
    })
}

override fun onDestroy() {
    super.onDestroy()
    DownloadManager.unregister(this)
}
  • DownloadManager 方法说明
Attribute 方法含义
downloadApk 下载APK
installApk 安装APK
installWithPermission 检查权限并安装
  • DownloadIntentService 说明
Attribute 方法含义
DOWNLOAD_ACTION_PROGRESS 下载进度广播
DOWNLOAD_ACTION_INSTALL 安装APK广播

upgrade's People

Contributors

freeler avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

hiboxgit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.