2

I'm trying to develop an android application like this Recycle Bin App on playstore where any file deleted from the android system is detected and shown in the recycle bin app from where it can be recovered (which they're probably doing it by making a copy of the file before it gets deleted).

I have tried using the android FileObserver and made a Recursive File Observer class like this one to catch system events for every file in the system but even that fails to work on some devices (e.g. Huawei Phones) and the delete event only gets called after the file gets deleted from the system. Another thing I tried is to make a file input stream for any file on which the File.Access or File.Open events are called and then making a copy of that file once the File.delete event is called. The problem here is that when using a third party File explorer (the one that comes along with the android OS), file events like access are not called unless you specifically open a file, so if user deletes a file without opening it first or if the user delete multiple files, we cannot capture those files before they get deleted.

   public void onEvent(int event, String path) {
     switch (event) {
           case RecursiveFileObserver.ACCESS:
                 makeInputStremForPath(path);
                 break;

        case RecursiveFileObserver.DELETE:
          copyFile(inputStrem);
          break;
        }
}

So, I'm looking for some ways to detect the deletion event on any file as it's about to get deleted from the system. I have researched a lot but didn't found any solution for this problem. There is another app named Dumpster on PlayStore which is doing this kind of a thing (although that too sometimes fails to recover files when deleted from a 3rd party file explorer). I've found this answer regarding some background on Dumpster app but still didn't find any definitive solution for my problem.

Qazi
  • 122
  • 6

0 Answers0