android file monitor

1

I need to develop an android application where it works by monitoring a certain directory with a certain periodicity and sending new files from that directory to an FTP or other folder on the local network that the device is connected to. Eg Every two minutes monitor the camera directory and whenever a user takes a new picture, this monitor will check for new photos and send to a local network directory. How to work with this type of app on android?

    
asked by anonymous 05.08.2015 / 14:04

2 answers

2

To track changes to an Android folder, use the FileObserver class >

A possible implementation would look like this:

public class FileMonitor extends FileObserver {

    public MyFileObserver(String path) {

        super(path, FileObserver.ALL_EVENTS);
    }

    @Override
    public void onEvent(int event, String path) {

        if (path == null) {
            return;
        }

        if ((FileObserver.CREATE & event)!=0) {

            //Foi criado um novo ficheiro ou uma nova pasta.
            //Introduza aqui o código para o tratamento que quer
            //efectuar para este caso 
        }

    }

}

In this example, you are only monitoring whether a new file or folder has been created within the monitored folder.

Other events can be monitored, see the documentation .

To use do:

FileMonitor monitor = new FileMonitor("/sdcard/minhaPasta/");
monitor.startWatching();

To stop monitoring use:

monitor.stopWatching();
    
05.08.2015 / 15:22
0

You will need a broadcast receiver that will give you the information that a new photo was taken. That is, whenever a photo is taken you will have such information and will call the upload code for FTP

If the photo example is your real problem you can try this: link

Inside the onReceive of your broadcast is where you should list the photos and search for the new photo.

    
05.08.2015 / 14:56