I’m trying to setup a file observer, but all I get is this error…
I’m trying to setup a file observer, but all I get is this error…
I don’t even know if we can have a fileobserver running in background with LL, but I’m trying..
TrianguloY Lukas Morawietz Pierre Hébert
]]>
< ![CDATA[
LL.bindClass(“android.os.FileObserver”)
function setupObserver(pathToWatch)
{
//ERROR IS HERE
var observer = new FileObserver(pathToWatch) {
// set up a file observer to watch this directory on sd card
onEvent: function(eventMask, filePath) {
if (eventMask == FileObserver.CREATE) {
Android.makeNewToast(filePath + ” created”, true).show();
} else {
Android.makeNewToast(“event ” + eventMask + ” for file ” + filePath).show();
}
},
};
return observer;
}
var observer = setupObserver(“/storage/emulated/0”);
observer.startWatching();
Android.makeNewToast(“setup complete”).show();
]]>
< ![CDATA[
Well after re-reading the docs, FileObserver is an abstract class, so I need to create a class that extends from FileObserver.. How can I do this in JS ?
]]>
< ![CDATA[
You need something called Java Adapter
I never used it, but it is something like
new JavaAdapter(FileObserver(pathToWatch),{ …} );
]]>
< ![CDATA[
TrianguloY how do you know this?
]]>
< ![CDATA[
Because Lukas Morawietz found it, but that function was obfuscated, and asked Pierre Hébert to not obfuscate it.
And I read the post 🙂
]]>
< ![CDATA[
Maybe it has something to do with the Java2JS engine.. Do you know his name?
]]>
< ![CDATA[
1. Yes, Java adapter would be the right thing to use, but
2. Java adapter doesn’t work on Android, because it needs Java bytecode.
3. I asked the developers of Rhino and they said: it would theoretically be possible to adjust this for android, but it’s a lot of work and it’s not planned.
4. The only way to extend a class is to ship it in an apk and then load it in the script.
]]>
< ![CDATA[
I see..
]]>