Hello. How can i use ContentObserver in Lightning Launcher? Can I get an example, if its possible?

Hello. How can i use ContentObserver in Lightning Launcher? Can I get an example, if its possible?

]]>
« (Previous Post)

7 Commentsto Hello. How can i use ContentObserver in Lightning Launcher? Can I get an example, if its possible?

  1. Anonymous says:

    < ![CDATA[

    Pierre Hébert​


    I think the challenge is that you have to extend the abstract Android class contentobserver before you can start instantiating your new, own class.



    How is extending done in LL java script? Is that possible at all?

    ]]>

  2. Anonymous says:

    < ![CDATA[

    Yes, using JavaAdapter (https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scripting_Java) and the genius work of Lukas Morawietz​ who made it possible to use it in Lightning. There are probably some sample uses of JavaAdapter in the script repository somewhere but I don’t know which.

    ]]>

  3. Anonymous says:

    < ![CDATA[

    Sample:


    bindClass(“android.util.AsyncTask”);


    var task = new JavaAdapter(AsyncTask,{


    doInBackground:function(args){


    //do something


    }


    });


    task.execute();

    ]]>

  4. Anonymous says:

    < ![CDATA[

    I had to change util to os to make the example work.



    I tried the same with contentobserver but got and exception, unfortunately.



    I tried:


    observer=new JavaAdapter(ContentObserver,{



    onChange:function(selfChange)


    {


    //alert(“observed”)


    }


    });



    And got:


    xxxJavaException: java.lang.NoSuchMethodException: [interface org.mozilla.javascript.Scriptable, class org.mozilla.javascript.ContextFactory]



    Broadcastreciever did work though (to listen for volume change events e.g.)

    ]]>

  5. Anonymous says:

    < ![CDATA[

    Karsten Franke


    I typed that from memory. Of course the correct package name is os.

    ]]>

  6. Anonymous says:

    < ![CDATA[

    Karsten Franke you can specify the constructor parameters this way:



    var adapter = new JavaAdapter(ArrayAdapter, {


    getView: function(position, convertView, parent) {


    blabla


    }


    }, context, layout, items);



    This will create an instance of a subclass of JavaAdapter with the context, layout and items constructor arguments.

    ]]>

  7. Anonymous says:

    < ![CDATA[

    Lukas Morawietz no problem at all.



    Pierre Hébert And we have a winner. Works like a charm. Big thanks.

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *