📜  kotlin 从 url 下载文件 - Kotlin 代码示例

📅  最后修改于: 2022-03-11 14:53:32.406000             🧑  作者: Mango

代码示例1
val downloadmanager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager?
        val uri: Uri = Uri.parse("http://www.example.com/myfile.mp3")

        val request = DownloadManager.Request(uri)
        request.setTitle("My File")
        request.setDescription("Downloading")
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
        request.setVisibleInDownloadsUi(false)
        request.setDestinationUri(Uri.parse("file://" + folderName.toString() + "/myfile.mp3"))

        downloadmanager!!.enqueue(request)