【发布时间】:2015-09-02 07:12:19
【问题描述】:
app的主要目标是使用URL从网络图像下载。目前图像下载良好,URL 链接运行良好。但是问题发生在将图像保存到设备存储中。 1.我的手机有SD卡,保存效果很好。 2. 我的平板电脑内置了 16Gb 的存储空间。在我的平板电脑上,图片是下载的,但没有保存。
图片保存源代码示例:
FileManager fileManager = new FileManager();
if (fileManager.fileExists(filename)) {
File file = fileManager.getFile(filename);
Uri fileUri = Uri.fromFile(file);
return new SaveImageRequest(fileUri);
} else {
String type = ".png"; //fallback to ".png"
if (path.toString().lastIndexOf(".") != -1) { //-1 means there are no punctuations in the path
type = path.toString().substring(path.toString().lastIndexOf("."));
}
DownloadManager.Request request = new DownloadManager.Request(path);
request.setTitle(notificationTitle);
request.setVisibleInDownloadsUi(false);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
request.allowScanningByMediaScanner();
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, "/DestinationDir/" + filename + type);
return new SaveImageRequest(downloadManager.enqueue(request));
}
您是否有任何解决方案可以将图像保存在具有内置存储设备和具有外部存储设备的设备上? PS:android访问存储的权限
【问题讨论】:
-
看来你应该包括你的
SaveImageRequest类
标签: java android android-sdcard android-external-storage