java在不同的Android设备(手机和平板电脑)上保存图像
应用程序的主要目标是使用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:安卓访问存储的权限
共 (0) 个答案