1

This is just something I am going to have to look at shortly so was wanting to get a headstart on the topic.

Currently I have a phonegap application which contains a load of HTML/JS files, as you would expect, however I am also going to want to support plugins. The plugins would contain new html/js files as well as other resources, and would expose a plugin contract model based off some interface. So you would install the main app, then lets say I decided to add a new plugin for X, they would then go to the marketplace and download the plugin app, which by itself is useless, but would be called upon via the main application.

Now after looking through the interwebs I found Write Plugin for Android App

which tells me how to go about loading a plugin at the android level, but the part which confuses me a bit is how can I get access to the html/js resources contained within that plugin. With .net and things you can pull resources from dlls but would I have to do this in Android or is there some nicer way to get access to the static files contained within the addons.

So the crux of this question is, how can I load static files from an installed plugin.

Community
  • 1
  • 1
Grofit
  • 17,693
  • 24
  • 96
  • 176

1 Answers1

1

I'm not sure that I understand your question clearly, but I guess you want to learn how you can trigger a function in your js files. If its the question here how I'm doing it. Hope it helps.

    private static void invokeJavascript(String javascriptFunctionName, String[] javaScriptParam) {

        StringBuilder buf = new StringBuilder("javascript:");

        buf.append(javascriptFunctionName);
        buf.append("('");

        for (int i = 0; i < javaScriptParam.length; i++) {
            buf.append(javaScriptParam[i]);
                buf.append("','");
        }

        buf.append("','nativeCallbackSuccess', 'nativeCallbackFail')");
        cordovaWebView.loadUrl(buf.toString());
  }
osayilgan
  • 5,873
  • 7
  • 47
  • 68
  • Ignoring the Html Phonegap bit and just talking in android, I want to make one main application which will be available by itself. Then however I want to write plugins for that application that users can install and it will add functionality to the main application. Much like ScummVM and its additional plugins, so every time you install one of the ScummVM plugins it adds functionality to the main application. The quirk around this though is that the application is written in Html and JS hosted as a native application via PhoneGap (or other similar platform). – Grofit Feb 05 '13 at 19:17
  • CordovaPlugin simply provides to you a communication between JS and Native Android. If you look at the Plugins in Apache's repository you will see that the Plugins consist of 2 parts, one is JS and the other one is Native Android. Once you want to add a plugin (functionality) to your android application, what you do is copying over the JS and Java codes to your application. So it works almost like you say, but depending on the plugin sometimes you also need to add some piece of code to your JS (to send commands to plugin) and Android. – osayilgan Feb 06 '13 at 13:32
  • Beside that, if you want to make an UI with HTML than you just need to trigger plugin according to your needs. But how I'm working is a bit different, my application is 100% native regarding to UI but I'm managing the data in the backend in JS. E.g I have a button on my native UI and I want to get the data from my DB of from a web service when I click on the button and update the UI according the received data and I want to use backend for that. – osayilgan Feb 06 '13 at 13:40
  • To accomplish that I create a data_controller.js file where I have functions that I can trigger from native, then when the function is triggered I simply go data base get required data and send it over to my plugin.js file which will trigger native part. So I have the data now in my Plugin (native) then I just send it back to my Activity to make it updates my UI through an Interface. – osayilgan Feb 06 '13 at 13:40