Created
October 13, 2021 13:31
-
-
Save ziginsider/63452b11716c8ca5fd3c81ed5b001afc to your computer and use it in GitHub Desktop.
Download to device by url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyDownloadManager { | |
fun downloadByUrl(context: Context, url: String) { | |
val fileName = url.substring(url.lastIndexOf('/') + 1) | |
val request = DownloadManager.Request(Uri.parse(url)).apply { | |
setTitle("image $fileName") | |
setDescription("From CatGallery") | |
setNotificationVisibility(VISIBILITY_VISIBLE_NOTIFY_COMPLETED) | |
setDestinationInExternalPublicDir(DIRECTORY_DOWNLOADS, fileName) | |
} | |
(context.getSystemService(DOWNLOAD_SERVICE) as DownloadManager).enqueue(request) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment