如何更改下载管理器中的文件路径-Android(Kotlin)



我正在尝试创建新文件,并将其替换为当前路径,如下所示:但带有->的行。setDestinationInExternalPublicDir("/NEW_files",名称+".png"(使我的应用程序崩溃;(

val direct = File(
Environment.getExternalStorageDirectory().toString() + "/NEW_files"
)
if (!direct.exists()) {
direct.mkdirs()
}

val request:DownloadManager.Request=DownloadManager.Request(
Uri.parse(url)
).setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationInExternalPublicDir("/NEW_files", name+".png")
.setAllowedOverMetered(true)

val dm:DownloadManager=getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
dm.enqueue(request)

你能试着看看这是否有效吗?

val request:DownloadManager.Request=DownloadManager.Request(
Uri.parse(url)
).setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, name+".png")
.setAllowedOverMetered(true)

最新更新