According to the onEvent() documentation :
Path relative to the main monitored file or directory of the file or directory that caused the event
So, I think when path is null , is the specified file or directory ...
You need to track the source path yourself. And add path of onEvent() to this path to get the full path (if you don't track the file, and its value is always null ):
FileObserver observer = new FileObserver(imageUri.getPath()) { public String basePath; @Override public void onEvent(int event, String path) { String fullPath = basePath; if(path != null) {
I tried to bring this example as close as possible to a piece of code. But it is much better to create a full-blown class that extends FileObserver , so you can add a constructor to store basePath and you donβt have to access a public field outside the class / instance!
source share