我使用這段代碼保存圖像:保存圖像庫的Android
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設備中顯示具有特定文件夾名稱的圖庫中的圖像。
請幫忙。
您需要在圖庫中添加圖像後刷新圖庫。 刷新庫: http://stackoverflow.com/questions/4144840/how-can-i-refresh-the-gallery-after-i-inserted-an-image-in-android –
@VipulPatel:sendBroadcast( (Intent.ACTION_MEDIA_MOUNTED,Uri.parse (「file://」 + Environment.getExternalStorageDirectory()))); 文件是文件路徑嗎? – android
你需要引用這個鏈接你的問題: http://stackoverflow.com/questions/3300137/how-can-i-refresh-mediastore-on-android –