【发布时间】:2016-10-08 08:31:34
【问题描述】:
我在 WebView 中加载我的网站,并使用下载管理器从我的网站下载照片文件。文件下载成功,我可以在内部存储/下载中找到该文件。
我使用 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。
任何想法为什么我的画廊中的图像文件路径显示不同的路径?以及如何解决这个问题?
【问题讨论】:
-
如果文件来自您的网站,您可以很好地比较文件。从文件大小开始。
-
I can found the file on Internal Storage/Download.。您是否告诉下载管理器将文件存储在哪里?或者你具体做了什么?请也说出确切的路径。我们怎么能比较其他人? -
when I open my gallery photo,。你具体做了什么?使用图库应用?更好的。你找到了你说的那个文件。您将在您的设备上使用文件资源管理器应用程序(如果没有,则告诉或执行)。让文件资源管理器打开文件。 -
你能告诉我图片的格式吗..@HengkyMulyono
-
@Shivam 格式为 JPG。
标签: android android-studio android-6.0-marshmallow