I use the line below to get thumbnail:
bitmap = MediaStore.Images.Thumbnails.getThumbnail(act.getApplicationContext().getContentResolver(), fid, MediaStore.Images.Thumbnails.MICRO_KIND, null);
And I try to rename file name with below code:
File rename = new File(oldname);
String newpath = newname;
rename.renameTo(new File(newname));
And use below code to update database:
IntentFilter intentfilter = new IntentFilter(Intent.ACTION_MEDIA_SCANNER_STARTED);
intentfilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
intentfilter.addDataScheme("file");
MediaScannerReceiver scanSdReceiver = new MediaScannerReceiver();
registerReceiver(scanSdReceiver, intentfilter);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory().getAbsolutePath())));
public class MediaScannerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals("android.intent.action.MEDIA_SCANNER_FINISHED")) {
bitmap = MediaStore.Images.Thumbnails.getThumbnail(act.getApplicationContext().getContentResolver(), fid, MediaStore.Images.Thumbnails.MICRO_KIND, null);
}
}
}
The file name change success, the file id also get the new one.
But the thumbnail showed was wrong one.
How to get the right one thumbnail?
It may cause by thumbnail does not be delete.
And the file which after rename one has the same id.
So show the old one’s thumbnail.
You may try to clean
/sdcard/DCIM/.thumbnailsfolder, and create new one.