Question

My app now has a background service that needs to check if there is any changes in some specific directories chosen by users. If there is any new files, it will be uploaded to a server (like syncing to your Dropbox folder), but if the user deletes a file from his device, the file on server will not be deleted. My problem is I can't find an effective way to detect changes.

I first used recursion to check folder size but clearly the performance is not good at all (the service have to recursively check folders after xxx minutes/seconds, record its size to compare to the next time...).

I tried using DownloadManager.ACTION_DOWNLOAD_COMPLETE, which turns out not a good option either. Firstly, new files can be copied, not only downloaded. Secondly, the broadcastreceiver can only receive requests send from my app, not from other apps or browsers). I check around Google and StackOverFlow but can only find how to scan for Media Files, I need more than that. Any suggestions?

Thanks in advanced.

Was it helpful?

OTHER TIPS

Your question is very hard to read, btw if your looking for folder size changes use this function,

This function will return you the size in particular folder.

public static long folderSize(File directory) {
    long length = 0;
    for (File file : directory.listFiles()) {
        if (file.isFile())
            length += file.length();
        else
            length += folderSize(file);
    }
    return length;
}

Source

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top