So, I'm trying to implement a download pdf feature for my app. Here is the code where i start the download manager.
val document = documents[i]
val request = DownloadManager.Request(Uri.parse("https://repository.bsi.ac.id/repo/files/256149/download/File_8-Bab-I-Pengenalan-Android.pdf"))
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
.setTitle("Downloading Pdf-Android")
.setMimeType("application/pdf")
.setDescription("File Description")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS,
"Pdf-Android.pdf"
)
val filter = IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
applicationContext.registerReceiver(DownloadReceiver(), filter)
downloadManager.enqueue(request)
After quite some times, the download launch but failed immediately, and i can't really debug it since the logcat doesn't display anything. I have tried to set the allowed network types into celluar, give the permission for writing external files.
I tried to use the method from the answer, but for some reason i don't get any information in logcat. But the download still unsuccessfull and no log is found on logcat
i already register the broadcast receiver on manifset like this
<receiver
android:name="somename.DownloadReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
</intent-filter>
</receiver>
It's a bit of an inconvenient situation; however, due to this code, we encounter the
DownloadManager.STATUS_PAUSEDerror (Reason log is Download failed: 1). I discovered the relevant information from this link: DownloadManager. Despite encountering this error, the documentation pertaining to it is also quite inadequate. I just added a method like this to detect the cause of the problem.