DownloadHelper

class DownloadHelper(context: Context)(source)

Centralized download helper based on Android's DownloadManager.

Handles file downloads to public or private directories with automatic progress tracking and system notifications.

Permissions:

  • No permissions required for public folder downloads on API 29+.

  • WRITE_EXTERNAL_STORAGE required on API < 29.

Example usage:

val downloadHelper = DownloadHelper(context)

val id = downloadHelper.enqueue(
DownloadConfig.publicFile(
url = "https://example.com/report.pdf",
fileName = "rapport.pdf"
)
)

// Observe completion
viewModelScope.launch {
downloadHelper.completionFlow(id).collect { status ->
if (status is DownloadStatus.Success) {
openFile(status.localUri)
}
}
}

Constructors

Link copied to clipboard
constructor(context: Context)

Functions

Link copied to clipboard
fun cancel(vararg ids: Long): Int
Link copied to clipboard

Flow émettant le DownloadStatus final (Success ou Failed) pour l'id donné. Se ferme automatiquement après émission.

Link copied to clipboard

Starts the download described by config. Returns the download ID.

Link copied to clipboard
Link copied to clipboard

Retourne le statut courant du téléchargement id.