Is it possible to set a listener on a created file and alert when the file size has reached a certain value.
Yes and no.
There is a class called FileObserver
which allows you to listen to certain events, for example when the file is opened, closes or modified. There is no specific listener for the file size, but either the MODIFY
or the CLOSE_WRITE
-event is suitable.
Have a look at the documentation: http://developer.android.com/reference/android/os/FileObserver.html
Short example:
observer = new FileObserver(pathToFile,MODIFY + CLOSE_WRITE)
@Override
public void onEvent(int event, String file) {
Log.d(TAG, "File changed[" + pathToWatch + file + "]");
//TODO: check file size...
}
};
observer.startWatching();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With