I have a Service which starts a FileObserver to monitor pictures which are taken by the phone camera, in particular thefile :
String initialPictureFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString() + "/Camera/";
by this function:
public void startFileObserver(String filePath){
/* It only monitors this Folder, not any Subfolder */
myFileOsberver = new PicturesFileObserver(filePath,UploadPhotosService.this);
myFileOsberver.startWatching();
}
that said, the FileObserver only catches delete events (code 512) and nothing more. Whenever I rename a file,move a file, or take a photo from the android camera, nothing happens. Am I missing anything ? Am I monitoring wrong file?
Here is the whole FileObserver class
private static int mask = FileObserver.ALL_EVENTS;
public PicturesFileObserver(String path,UploadPhotosService myService) {
super(path,mask);
this.rootDir = path;
this.myService = myService;
Log.e(TAG,"Observer is initialized on: "+rootDir);
}
@Override
public void onEvent(int event, @Nullable String path) {
event &= FileObserver.ALL_EVENTS;
Log.e(TAG,String.valueOf(event)); // ONLY PRINTS 512
if (path != null) {
if (path.endsWith(".jpg") || path.endsWith(".png")) {
if ((event == FileObserver.CREATE)) {
Log.e(TAG, "File was created " + path);
} else if ((FileObserver.MODIFY & event) != 0) {
Log.e(TAG, "File was modified " + path);
} else if ((FileObserver.DELETE & event) != 0) {
Log.e(TAG, "File was deleted " + path);
} else if ((FileObserver.MOVED_FROM & event) != 0) {
Log.e(TAG, "File was brought here " + path);
} else if ((FileObserver.MOVED_TO & event) != 0) {
Log.e(TAG, "File was brought here " + path);
}
} else
Log.e(TAG, "Path not beeing a photo: " + path);
}
}