我在android中使用DownloadManager API成功下载了一个pdf文件.
正确设置清单权限.
文件下载正确.
但当试图打开它时说“无法打开文件”.
请帮忙打开下载的文件.我想我没有为文件设置正确的名称和扩展名.怎么设置呢?
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);
}
最佳答案
原文链接:https://www.f2er.com/android/431104.html