BroadCast Receiver or Sync Adapter for detection o

2019-08-10 14:06发布

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条回答
在下西门庆
2楼-- · 2019-08-10 14:52

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 
查看更多
登录 后发表回答