Android需要帮助从Web排序保存图像

时间:2013-02-02 17:07:53

标签: android image gallery datecreated

从网络保存图片时出现问题。

我创建新文件夹并将所有图像保存到此。问题是我希望首先通过上一个下载图像来命令此文件夹,但是当我打开图库时,文件夹按创建的图像日期排序,下载图像中创建的日期不是我下载但是第一次创建的时间。我已经在堆栈上搜索流量,看到java无法将图像中创建的日期修改为我下载的时间。

有人有解决方案吗? (抱歉英文不好)

感谢您的评论。我会解释更多细节。

首先,我将图像从Web下载到缓存目录

HttpURLConnection localHttpURLConnection = (HttpURLConnection) new java.net.URL(urldisplay).openConnection(); 
localHttpURLConnection.setConnectTimeout(30000);
localHttpURLConnection.setReadTimeout(30000);
localHttpURLConnection.setInstanceFollowRedirects(true);
InputStream in = localHttpURLConnection.getInputStream();
File localFile = Constans.fileCache.getCacheFile(urldisplay);
FileOutputStream fos = new FileOutputStream(localFile);
Utils.CopyStream(in, fos); // simple copy by trunks
fos.close();

其次,我将下载的图像复制到外部存储

File toFile = new File(Environment.getExternalStorageDirectory() + "/folder", "folder_" + System.currentTimeMillis() + ".png");
FileOutputStream fos = new FileOutputStream(toFile);
Utils.CopyStream(new FileInputStream(fromFile), fos);
fos.close();

// Scan image to display when open with gallery otherwise it couldn't see in gallery
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(toFie);
mediaScanIntent.setData(contentUri);
mContext.sendBroadcast(mediaScanIntent);

最后,我看到该库在我下载时不会对图像进行排序。这是我想解决的问题。

1 个答案:

答案 0 :(得分:0)

不确定我理解,但试试吧。

首先,您提到的问题比Gallery代码问题更具体。 我假设Gallery使用EXIF信息按照拍摄日期对照片进行排序,而不是下载/复制它们。不幸的是,Gallery不提供任何选项来对其他oders中的图片进行排序。

也许您可以尝试使用另一个浏览器,它允许您按照其他顺序对图片进行排序(也许ESFileExplore有更多选项?)

终极解决方案:您可以尝试使用java EXIF库更改图片中的EXIF以修改拍摄日期,这应该会改变它们在Galery中出现的顺序(但非常难看的解决方案......)。谷歌5秒后的一些随机EXIF库: http://drewnoakes.com/code/exif/ http://www.toanthang.net/modules.php?name=News&new_topic=2&catid=7

希望这会有所帮助 亨利