所以,我试图为我的应用程序实现一个下载PDF功能。下面是我启动下载管理器的代码。
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)
字符串
经过相当长的一段时间,下载启动,但立即失败,我不能真正调试它,因为logcat不显示任何东西.我已经尝试将允许的网络类型设置为celluar,给予写入外部文件的权限.
我试着使用答案中的方法,但由于某种原因,我在logcat中没有得到任何信息。但下载仍然不成功,logcat上没有找到任何日志
我已经在manifset上注册了广播接收器,就像这样
<receiver
android:name="somename.DownloadReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
</intent-filter>
</receiver>
型
1条答案
按热度按时间92vpleto1#
这是一个有点不方便的情况;然而,由于这段代码,我们遇到了
DownloadManager.STATUS_PAUSED
错误(原因日志是 * 下载失败:1*).我发现了相关信息从这个链接:DownloadManager.尽管遇到了这个错误,有关它的文档也是相当不足.我只是添加了这样一个方法来检测问题的原因.字符串