我成功下载了使用Android中的DownloadManager API的pdf文件。无法打开通过下载管理器api下载的文件
清单权限设置是否正确。 文件正确下载。
但是当它试图打开它说:“无法打开文件”。
请帮忙打开下载的文件。我想我没有为文件设置正确的名称和扩展名。如何设置它?
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);
}
请在您尝试确定文件名的位置显示代码并打开文件。 – greenapps
我不试图从我的应用程序中打开文件。 pdf将被下载到下载文件夹中,并从那里用户手动打开它。该下载的文件没有被打开。 –
您在if循环中和第三行到最后一行中复制了'''request.allowScanningByMediaScanner();'''行。 –