1
打开下载的文件我在WebView中加载我的网站,并使用下载管理器从我的网站下载照片文件。文件下载成功,我可以在内部存储/下载中找到该文件。无法从downloadManager Android 6.0 Marshmallow
我将文件存储使用Environment.DIRECTORY_DOWNLOAD下载目录,这是我下载完整的代码文件:
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {
if(isStoragePermissionGranted()) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimeType);
//------------------------COOKIE!!------------------------
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
//------------------------COOKIE!!------------------------
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOAD, URLUtil.guessFileName(url, contentDisposition, mimeType));
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show();
}
}
});
但是当我打开我的图片库的照片,我无法打开照片。它说当我点击照片时“无法打开”。我检查文件的详细信息,文件路径参考/ storage/emulated/0/Download。
任何想法为什么我的画廊中的图像文件路径显示不同的路径?以及如何解决这个问题?
那么,如果该文件来自于你的网站,你可以很好地比较文件。从文件大小开始。 – greenapps
'我可以在内部存储/下载中找到该文件。 '。你告诉下载管理器在哪里存储文件?或者你做了什么?并请告诉确切的路径。我们怎么能比较其他? – greenapps
'当我打开我的画廊照片时,'。你究竟做了什么?使用图库应用程序?更好。你找到了你说的文件。你将在你的设备上使用一个文件浏览器应用程序(如果没有,那么告诉或做)。让文件资源管理器打开文件。 – greenapps