Reputation: 71
I'm working on this these days...
My app delete somes files by itself. But when I connect my phone with PC by MTP mode, the files which have been delete are still 'alive', but cannot be copied or opened.
I know infact the files are already deleted, but I have to refresh MTP. I have tried the following method:
MediaScannerConnection.scanFile(getApplicationContext(), paths, null, null);
but it doesn't work...
Does anybody here knows how to fix this issue? Thanks!
Upvotes: 0
Views: 922
Reputation: 5230
When you delete a file, Call refreshSystemMediaScanDataBase() method just after delete call trigger to refresh media
/**
@param context : it is the reference where this method get called
@param docPath : absolute path of file for which broadcast will be send to refresh media database
**/
public static void refreshSystemMediaScanDataBase(Context context, String docPath){
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(new File(docPath));
mediaScanIntent.setData(contentUri);
context.sendBroadcast(mediaScanIntent);
}
Upvotes: 2