0

It has been a long time since I stopped by this problem: my FileObserver's onEvent method is not triggered, tested, and not even the "method entered" toast is being displayed.

FileObserver fileObserver = new FileObserver(android.os.Environment.getExternalStorageDirectory().toString() + "/Pictures/Screenshots") {
    @Override
    public void onEvent(int event, String path) {

        Toast.makeText(getApplicationContext(), "method entered", Toast.LENGTH_SHORT).show();

        if (event == FileObserver.CREATE) {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(getApplicationContext(), "File created", Toast.LENGTH_SHORT).show();
                }
            });
        }
    }
};

fileObserver.startWatching();

Help me please! Thanks in advance.

1 Answers1

0

Check existence of file prev, it should cause issue.

public void startWatching ()

Added in API level 1 Start watching for events. The monitored file or directory must exist at this time, or else no events will be reported (even if it appears later). If monitoring is already started, this call has no effect.

J.Doe
  • 1