This question is extension of this question. Posting another question because that is closed.
I am implementing the FileObserver Class as mentioned by @SushiHangover but when the event (OnEvent) is fired then the value of path is null and the value of e is 1073741856.
This is how I am initializing the FileObserver as suggested by @SushiHangover
[Activity(Label = "Main Menu")]
public class MainView : MvxActivity
{
public MusicFolderObserver MusicFolderObserver;
protected override void OnViewModelSet()
{
File musicFolder = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryMusic), "/MyFolder");
MusicFolderObserver = new MusicFolderObserver (musicFolder.AbsolutePath);
MusicFolderObserver.StartWatching();
SetContentView(Resource.Layout.View_Main);
}
}
and following is the File observer Class
public class MusicFolderObserver : FileObserver
{
static FileObserverEvents _Events = (FileObserverEvents.AllEvents);
const string tag = "StackoverFlow";
public MusicFolderObserver (String rootPath) : base(rootPath, _Events)
{
Log.Info(tag, String.Format("Watching : {0}", rootPath));
}
public MusicFolderObserver (String rootPath, FileObserverEvents events) : base(rootPath, events)
{
Log.Info(tag, String.Format("Watching : {0} : {1}", rootPath, events));
}
public override void OnEvent(FileObserverEvents e, String path)
{
Log.Info(tag, String.Format("{0}:{1}", path, e));
}
}
Please let me know how can I make this observer active for the entire duration the app is running. I am trying to make an app which is active 24/7 and triggers if there is any change in the observed Music folder