BroadCast Receiver or Sync Adapter for detection of deletion of files at particular Location Android

风格不统一 提交于 2020-01-16 05:32: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:


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 


来源:https://stackoverflow.com/questions/35676003/broadcast-receiver-or-sync-adapter-for-detection-of-deletion-of-files-at-particu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!