Bạn định cấu hình đối tượng DownloadManager.Request với loại thông tin đó. Trong hướng dẫn, đối tượng Request
được tạo và sử dụng trong onClick()
.
Ví dụ:
DownloadManager.Request req=new DownloadManager.Request(uri);
req.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI
| DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setTitle("Demo")
.setDescription("Something useful. No, really.")
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
"test.mp4");
(trên code đang từ this sample project)
Dòng cuối cùng là thư quan trọng :) Lúc đầu, tôi đã hiểu một chút về điều đó. –
Hi CommonsWare Tôi vẫn không chắc chắn về cách nói cho DownloadManager thư mục nào để lưu trữ các tệp trong: ( Giống như bạn sẽ làm trong Async OutputStream output = new FileOutputStream ("/ sdcard/Myfolder/file_name.extension") ; – Mich
@Mich: 'setDestinationInExternalPublicDir()' và các phương thức liên quan cho phép bạn chỉ định thư mục đầu ra dưới dạng 'Tệp', không phải là' OutputStream'. – CommonsWare