【发布时间】:2018-05-26 19:32:03
【问题描述】:
在我的应用程序中,我想从服务器下载图像并将其存储到 SD 卡。
我写了下面的代码,我可以下载并存储在 SD 卡上。
但是将图像存储到 SD 卡后不会显示到图库中!
我的代码:
private void createDirectoryAndSaveFile(Bitmap imageToSave, String fileName) {
File direct = new File(Environment.getExternalStorageDirectory() + "/MyApp/Wallpaper");
if (!direct.exists()) {
File wallpaperDirectory = new File("/sdcard/MyApp/Wallpaper/");
wallpaperDirectory.mkdirs();
}
File file = new File(new File("/sdcard/MyApp/Wallpaper/"), fileName);
if (file.exists()) {
file.delete();
}
try {
FileOutputStream out = new FileOutputStream(file);
imageToSave.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
showReturnMessage("Message","Successfully saved :) ",R.color.alertSuccess);
} catch (Exception e) {
e.printStackTrace();
}
}
怎么可能?
【问题讨论】:
-
你是 #12345 这个问题。您必须调用媒体扫描程序来告诉媒体存储您的新图像文件。 Google... 或者重新启动您的设备,然后查看 Gallery 是否知道您的文件。
-
how to show image after store image into sd card on android。当您的意思是它没有显示在画廊中时,这是一个错误的主题。 -
@greenapps,我知道重启手机时会显示图像,但我不重启手机。我想不用重启手机,你能帮我发个代码吗?请
标签: java android android-gallery