1

I want a broadcast receiver that detects for deletion of files at particular location in android. Basically there are some files downloaded by the app whom I want to keep track of. As they gets deleted it should also be deleted from the local apps database. And if its possible a way to track when the file has moved from one location to another and is still present in the phone to get its current location. Please help.

1 Answers1

2

I think you can use FileObserver for this. Just observe the files you need.

Here's an example from this previous post: How do you implement a FileObserver from an Android Service.

 observer = new FileObserver(pathToWatch) { // set up a file observer to watch this directory on sd card

     @Override
     public void onEvent(int event, String file) {
         //if(event == FileObserver.CREATE && !file.equals(".probe")){ // check if its a "create" and not equal to .probe because thats created every time camera is launched
         Log.d(TAG, "File created [" + pathToWatch + file + "]");

         Toast.makeText(getBaseContext(), file + " was saved!", Toast.LENGTH_LONG);
         //}
     }
 };
 observer.startWatching(); //START OBSERVING 
Community
  • 1
  • 1
jbrulmans
  • 975
  • 1
  • 11
  • 32