【发布时间】:2015-07-04 05:04:51
【问题描述】:
我正在使用此代码保存图像:
URL url = null;
try {
url = new URL("image");
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
Bitmap bmp = null;
try {
bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e1) {
e1.printStackTrace();
}
OutputStream output;
File filepath = Environment.getExternalStorageDirectory();
File dir = new File(filepath.getAbsolutePath() + "/folder name/");
dir.mkdirs();
File file = new File(dir, image + ".png");
Toast.makeText(HomeActivity.this, "Image Saved to SD Card", Toast.LENGTH_SHORT).show();
try {
output = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 100, output);
output.flush();
output.close();
}
catch (Exception e) {
e.printStackTrace();
}
问题是当此代码在棒棒糖设备上运行时,图片未显示在图库中。我必须安装文件管理器才能检查这些图像。
使用此代码:
MediaStore.Images.Media.insertImage(getContentResolver(), bmp, "image";
图像保存在相机文件夹中。
我想在所有 android 设备中显示具有特定文件夹名称的图库中的图像。
请帮忙。
【问题讨论】:
-
在图库中添加图片后需要刷新图库。刷新图库:stackoverflow.com/questions/4144840/…
-
@VipulPatel: sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse ("file://" + Environment.getExternalStorageDirectory())));文件是文件路径?
-
您的问题需要参考此链接:stackoverflow.com/questions/3300137/…