및 OutputStream
을 사용하여 res/drawable
에서 Gallery
까지 이미지를 저장하고 있습니다. 그것은 잘 작동하고 이미지를 저장합니다. 하지만 문제는 갤러리의 이미지를 업데이트하지 않는다는 것입니다. ES File Explorer
을 사용하여 폴더를 확인하면 거기에 이미지가 표시됩니다. 나는 또한 ddms
을 확인했는데, write
코드를 실행하자마자 이미지를 업데이트했다.
서버 이미지를 저장하면 정상적으로 작동합니다. 이 문제를 방지하는 방법은 무엇입니까? 이미지 저장과 동시에 갤러리를 업데이트하고 싶습니다. MediaScanner
도 폴더를 검사했지만 아무런 효과가 없습니다.
내 코드 : 당신의 sdcard에 외부 폴더를 만든 다음 그 다음 GALLARY에 표시 코드 아래 사용하지저장된 이미지는 갤러리 안드로이드에서 볼 수 없습니다.
Toast.makeText(context, "Downloading Image...\nPlease Wait.",
Toast.LENGTH_LONG).show();
File direct = new File(Environment.getExternalStorageDirectory()
+ "/Images");
if (!direct.exists()) {
direct.mkdirs();
}
DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy-HHmmss");
Date date = new Date();
String CurrentDateTime = dateFormat.format(date);
InputStream input = null;
OutputStream output = null;
try {
input = context.getResources().openRawResource(
context.getResources().getIdentifier(
"@drawable/" + picName, "drawable",
context.getPackageName()));
output = new FileOutputStream(direct + "/" + "IMG-"
+ CurrentDateTime + ".jpg");
byte[] buf = new byte[1024];
int len;
while ((len = input.read(buf)) > 0) {
output.write(buf, 0, len);
}
MediaScannerConnection.scanFile(context,
new String[] { direct.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
Toast.makeText(context, "Image Saved.", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e("Internal Image Save Error->", e.toString());
Toast.makeText(context,
"Couldn't Save Image.\nError:" + e.toString() + "",
Toast.LENGTH_LONG).show();
} finally {
try {
if (input != null) {
input.close();
}
if (output != null) {
output.close();
}
} catch (IOException ignored) {
Log.e("Internal Image Save Error->", ignored.toString());
Toast.makeText(
context,
"Couldn't Save Image.\nError:" + ignored.toString()
+ "", Toast.LENGTH_LONG).show();
}
}
@ZerO, 내 게시물은 이미지 저장 방법이 아닙니다. 그것은 갤러리 업데이트에 관한 것입니다. – CSAT
예. 그리고 지금 복제물에있는 내용을 읽어보십시오. – PKlumpp