BroadCast Receiver or Sync Adapter to detect file deletion at a specific Android location

I want the broadcast receiver to detect file deletion in a specific location in android. Mostly there are files uploaded by the application I want to track about. As they are deleted, they must also be deleted from the local application database. And if this is a possible way to track when a file has moved from one place to another and is still present on the phone to get its current location. Please help.

+1
android broadcastreceiver android-syncadapter
source share
1 answer

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

Here is an example from a previous post: How to implement 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 
+2
source share

All Articles