[英]how to set name of my choice in downloading file from Url
我想在從 Url 下載文件時設置我選擇的名稱。
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(URL));
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN){
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
DownloadManager downloadManager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
request.allowScanningByMediaScanner();
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
downloadManager.enqueue(request);
您可以在 subPath 中設置您的文件名
val request = DownloadManager.Request(Uri.parse(url))
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI or
DownloadManager.Request.NETWORK_MOBILE)
request.setTitle("Download")
request.setDescription("The File is Downloading..")
request.allowScanningByMediaScanner()
request.setMimeType("application/pdf")
request.setNotificationVisibility
(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
"${System.currentTimeMillis()}" + ".pdf")
// get download service and enqueue file
val manager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
manager.enqueue(request)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.