downloadFile

inline fun Context.downloadFile(url: Uri, fileName: String, userAgent: String? = null, title: String = fileName, description: String? = null, mimeType: String? = null, notificationMode: Int = DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED, directory: String = Environment.DIRECTORY_DOWNLOADS, onFailure: (Exception) -> Unit)

Saves file using DownloadManager to users /sdcard/directory

Parameters

notificationMode

an int flag specified in DownloadManager.Request outlining the notification visibility. If enabled, the download manager posts notifications about downloads through the system NotificationManager. By default, a notification is shown only when the download is in progress. It can take the following values: VISIBILITY_HIDDEN, VISIBILITY_VISIBLE, VISIBILITY_VISIBLE_NOTIFY_COMPLETED. If set to VISIBILITY_HIDDEN, this requires the permission Manifest.permission.DOWNLOAD_WITHOUT_NOTIFICATION

directory
onFailure

is called if there was an exception. Possible exceptions are: - ActivityNotFoundException - SecurityException - when permission to write to storage was not granted - IllegalStateException - when provided parameters are invalid (i.e. download directory can't be created)