だからここにシナリオがあります
フォルダーを反復処理し、すべての画像を別の画像セットに置き換えます。
私が期待すること: サムネイルだけでなく、ギャラリーでも画像が更新されます。
得られるもの : ギャラリーを開くと、古い画像のサムネイルがまだ残っています。画像を開くと、その画像の置き換えられたバージョンが表示されます。さらに奇妙なことに、いくつかの画像を開くと、以前の元の画像がすばやく点滅し、その後に置き換えられたバージョンが表示されます。その写真を拡大すると、「驚き」、古い写真です。もう一度(注:これは一部の画像のみです。すべてではありません)。ただし、すべての画像のサムネイルは更新されていません。
10 分ほど待つと、すべての画像が更新され、古い元の画像の痕跡がなくなりました。
瞬時に実行しない理由はわかりません。
こちらの指示にも従いました。しかし、同じ問題が続きます。フォルダー全体のスキャンをトリガーする最新の API では、システムがそれを行う以外にフォルダー全体をスキャンすることはできません。
マイコード
//originalImagesList is the list of filepaths for all the images in a specific folder
for (String s :originalImagesList)
{
try
{
File checkIfFile = new File(s);
//replacementAppImg contains a list of images used to replace other images with
Log.v(TAG, "Moving file From Replace - " + replacementAppImg.get(1));
Log.v(TAG, "Moving file to Replace - " + s);
InputStream in = new FileInputStream(replacementAppImg.get(1)); //From where
OutputStream out = new FileOutputStream(s); //To where
//Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
Intent mediaScannerIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
//checkIfFile is the new replaces image that i want to refresh/check
Uri fileContentUri = Uri.fromFile(checkIfFile);
mediaScannerIntent.setData(fileContentUri);
CustomSettings.getCustomAppContext().sendBroadcast(mediaScannerIntent);
} catch (Exception ex) {
Log.v(TAG2,"Exception 1 - " + ex.toString());
}
}