Skip to content

DownloadWithSystem

StormKid edited this page Jul 2, 2019 · 2 revisions

直接使用:

fun doDownloadApk(){
Okkt.instance.download(
            "url",
            "appName",
            "discribe",
            context,
            object : DownLoadRule {
                override fun onFinished(uri: Uri?, broadcastReceiver: BroadcastReceiver) {
                    unregisterReceiver(broadcastReceiver)
                    if (uri!=null){
                        val intent = Intent(Intent.ACTION_INSTALL_PACKAGE)
                        intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
                        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
                        intent.setDataAndType(uri, "application/vnd.android.package-archive")
                        startActivity(intent)
                    }
                    Toast.makeText(this@HomeActivity,"准备安装",Toast.LENGTH_SHORT).show()
                    update.isEnabled = true
                }

                override fun onNetErr() {
                    Toast.makeText(this@HomeActivity, "下载安装失败,请检查权限", Toast.LENGTH_LONG).show()
                    update.isEnabled = true
                }
            }
        )
}
Clone this wiki locally