我正在使用以下代码保存图片:
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";
照片保存在相机文件夹中。
我想在所有安卓设备中以特定的文件夹名称在相册中展示照片。
请帮忙。