1

How to update the media database when we delete a file. am developing an file explorer app, so I need to update media database in android?

This link How to update the Android media database was helpful to me. but what I need is to scan the specific path or location in sdcard.

If every time I run this it will take more time, so is there any way to scan a specific path? like it should scan only "/sdcard/DCIM/onefolder/" files present in the folder named "onefolder".

Community
  • 1
  • 1

1 Answers1

0

With this class you can scan a single file:

import java.io.File;
import android.content.Context;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.net.Uri;

public class SingleMediaScanner implements MediaScannerConnectionClient {

private MediaScannerConnection mMs;
private File mFile;

public SingleMediaScanner(Context context, File f) {
    mFile = f;
    mMs = new MediaScannerConnection(context, this);
    mMs.connect();
}

@Override
public void onMediaScannerConnected() {
    mMs.scanFile(mFile.getAbsolutePath(), null);
}

@Override
public void onScanCompleted(String path, Uri uri) {
    mMs.disconnect();
}

}

Then just call it like this:

new SingleMediaScanner(this, file);
Noureddine AMRI
  • 2,942
  • 1
  • 21
  • 28
  • thanks for the above suggestion, but it is only working for a single file. it is not working when the file is in a folder like file name: image.jpg which is in the folder name Folder where its path is /mnt/sdcard/Folder. what i need is in my file explorer app i want to delete the folder named Folder itself. so after deleting folder it should remove information of the files from media database but it is not removing information. – Invinci Andro Dec 16 '11 at 08:24
  • can't you access all the files in this folder, then removing them one by one. – Noureddine AMRI Dec 16 '11 at 09:39
  • this is a 1:1 copy of @Petrus' answer here http://stackoverflow.com/a/5815005/1545993... others call this plagiarism... – Taifun Nov 14 '15 at 16:57