Hello everyone, I tried using the Download Manager...
# android
k
Hello everyone, I tried using the Download Manager API in my project, and it worked well on android 10+ but on android 9 and below when you try to download, nothing happens even in the logcat I get nothing, here is my Code
Copy code
fun downloadVideo(videoUrl: String, context: Context, downloadManager: DownloadManager, videoTitle: String) {    val videoUri = videoUrl.toUri()
    val moviesDir = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), "Movies")    moviesDir.mkdirs()
    val videoFile = File(moviesDir, videoTitle)
    val request = DownloadManager.Request(videoUri)        .setTitle(videoTitle)
        .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)        .setAllowedOverMetered(true)
        .setAllowedOverRoaming(true)        .setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE or DownloadManager.Request.NETWORK_WIFI)
        .setMimeType("video/mp4")        .addRequestHeader("Authorization", "Bearer <token>")
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {        // Use setDestinationUri for Android 10 and above
        request.setDestinationUri(videoFile.toUri())    } else {
        // Use setDestinationInExternalPublicDir for Android 9 and below        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_MOVIES, "Movies/$videoTitle")
    }
    downloadManager.enqueue(request)}
not kotlin but kotlin colored 4