Search code examples
androidbroadcastreceiverandroid-file

android code to detect if there is any changes in the contents of a folder


Is there any way that i can detect if there is a change in the contents of a folder which is in android device storage?

i want to detect if the user adds files to that folder, i what to perform some action.How can i do this?

Actually my exact requirement is, whenever the user saves data in my app, i want that to be uploaded to my server. so if there is a change in that specific folder, i'll run the upload activity. Any help please.

In Short: whenever there is a changes in the contents of the folder i what to trigger another event. i want the changes in the folder be the trigger. Any help will be appreciated. Thanks.


Solution

  • use FileObserver http://developer.android.com/reference/android/os/FileObserver.html. You might need to make it recursive to catch sub-directories