Почему ничего не загружается?

#android #android-studio #kotlin #android-download-manager #download-manager

Вопрос:

То, что я пытаюсь сделать, — это загрузить базовый pdf-файл всякий раз, когда я нажимаю кнопку. Когда я нажимаю кнопку, я получаю текстовый индикатор «готово», но ничего не загружается

 btn_download.setOnClickListener {  var downloadRequest = DownloadManager.Request(  Uri.parse ("http://www.africau.edu/images/default/sample.pdf"))  .setTitle("a pdf")  .setDescription("a pdf")  .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)  //over data  .setAllowedOverMetered(true)  .setAllowedOverRoaming(true)  val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager   downloadID = downloadManager.enqueue(downloadRequest)  }   var receiver = object:BroadcastReceiver(){  override fun onReceive(context: Context?, intent: Intent?) {  var id= intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)  if (downloadID == id){  Toast.makeText(applicationContext, "done",Toast.LENGTH_LONG).show()  }  }  }  registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))  

Комментарии:

1. Попробуйте явно добавить пункт назначения в свой запрос с помощью .setDestinationInExternalPublicDir() или аналогичного.

2. .setDestinationInExternalPublicDir( Среда. DIRECTORY_DOWNLOADS, «/» context.getString(R. строка.имя приложения) «/» Имя файла )