【发布时间】:2017-08-18 09:40:29
【问题描述】:
1) 通过下载管理器在 android studio 中下载 .docx/pdf 文件后,它会显示一条消息“文件中的内容不可读。你想恢复它吗?”
2) 但是当我下载 jpg 或 mp3 时,它工作正常。
我的代码:
private long DownloadData (Uri uri, View v) {
long downloadReference;
downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(uri);
//Setting title of request
request.setTitle("ZoraizCV");
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
//Setting description of request
request.setDescription("Android Data download using DownloadManager.");
//Set the local destination for the downloaded file to a path within the application's external files directory
if(v.getId() == R.id.DownloadMusic)
request.setDestinationInExternalFilesDir(MainActivity.this, Environment.DIRECTORY_DOWNLOADS,"zoraizCV.docx");
request.allowScanningByMediaScanner();
//Enqueue download and save the referenceId
downloadReference = downloadManager.enqueue(request);
Button DownloadStatus = (Button) findViewById(R.id.DownloadStatus);
DownloadStatus.setEnabled(true);
Button CancelDownload = (Button) findViewById(R.id.CancelDownload);
CancelDownload.setEnabled(true);
return downloadReference;
}
【问题讨论】:
-
你得到这个问题的答案了吗?
标签: android pdf android-download-manager download-manager