Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File System Listener

Tags:

android

I would like to know if it is possible to have a listener in my application for notifying events when a file is added to the file system. Can someone kindly guide me with this.

Thanks in advance.

like image 822
S.A.Norton Stanley Avatar asked Aug 03 '11 12:08

S.A.Norton Stanley


2 Answers

You should use a FileObserver to monitor for changes to files or directories.

There seems to be an example here, but I've not tried it so can't vouch for it's correctness.

like image 126
RivieraKid Avatar answered Sep 17 '22 17:09

RivieraKid


try this:

new FileObserver(path) {
    @Override
    public void onEvent(int event, String path) {
        if (event == FileObserver.CREATE)
            Toast.makeText(getActivity(), "File created", Toast.LENGTH_SHORT).show();
        }
    }.startWatching();
like image 22
Amjad Abu Saa Avatar answered Sep 18 '22 17:09

Amjad Abu Saa