I am making an audio recorder app, when i delete the recording file from the directory manually and when i open the app its should remove the deleted file from the Recycler List view any answer how to do this?
public class ObserveFiles extends FileObserver { public RecyclerViewAdapter recyclerViewAdapter;
public String absolutePath;
public ObserveFiles(String path) { super(path, FileObserver.ALL_EVENTS);
absolutePath = path;
}
..............................................................................
@Override public void onEvent(int event, @Nullable String path) {
if (path == null) {
return;
}
//a new file or subdirectory was created under the monitored directory
if ((FileObserver.DELETE & event)!=0) {
Log.d("Deleted---------->", "File Deleted [" + absolutePath + "/" + path + "]");
String filepath = absolutePath + "/" + path;
recyclerViewAdapter.removeOutOfApp(filepath);
}
//data was written to a file
if ((FileObserver.MODIFY & event)!=0) {
Log.d("Deleted---------->", "File Modified [" + absolutePath + "/" + path + "]");
}
//the monitored file or directory was deleted, monitoring effectively stops
if ((FileObserver.DELETE_SELF & event)!=0) {
Log.d("Deleted---------->", "File Self Deleted [" + absolutePath + "/URecorder" + "/" + path + "]");
}
//a file or directory was opened
if ((FileObserver.MOVED_TO & event)!=0) {
Log.d("Deleted---------->", "File Moved To [" + absolutePath + "/" + path + "]");
}
//a file or subdirectory was moved from the monitored directory
if ((FileObserver.MOVED_FROM & event)!=0) {
Log.d("Deleted---------->", "File Moved From [" + absolutePath + "/" + path + "]");
}
//the monitored file or directory was moved; monitoring continues
if ((FileObserver.MOVE_SELF & event)!=0) {
Log.d("Deleted---------->", "File Moved Self[" + absolutePath + "/" + path + "]");
}
}