Tôi đã tải xuống thành công tệp pdf bằng API DownloadManager trong Android.không thể mở tệp tải xuống thông qua trình quản lý tải xuống api
Quyền kê khai được đặt chính xác. Tệp được tải xuống chính xác.
Nhưng khi nó được cố gắng mở nó nói "không thể mở tệp".
Vui lòng trợ giúp để mở tệp đã tải xuống. Tôi đoán tôi đã không đặt tên và phần mở rộng thích hợp cho tệp. Làm thế nào để thiết lập nó?
private void DownloadBook(String url, String title){
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
//request.setDescription("Some descrition");
String tempTitle = title.replace(" ","_");
request.setTitle(tempTitle);
// in order for this if to run, you must use the android 3.2 to compile your app
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, tempTitle+".pdf");
// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
request.setMimeType(".pdf");
request.allowScanningByMediaScanner();
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
manager.enqueue(request);
}
Vui lòng hiển thị mã nơi bạn cố gắng xác định tên tệp và mở tệp. – greenapps
Tôi không cố gắng mở tệp từ ứng dụng của mình. Pdf sẽ được tải xuống vào thư mục tải xuống và từ đó người dùng mở thủ công nó. Tệp đã tải xuống đó không được mở. –
Bạn đã nhân đôi dòng '' 'request.allowScanningByMediaScanner();' '' bên trong vòng lặp if của bạn và trên dòng thứ ba đến dòng cuối cùng. –