Developing a Plugin on Bada

Plugins are only supported on Bada 2.0 and above. Bada 1.2 does not support plugins.

The Bada implementation is a full javascript implementation. Therefore, adding a custom plugin involves updating CordovaJS with your plugin code. Follow these steps to add a simple Hello World plugin:

  1. Clone the CordovaJS repository

     git clone https://git-wip-us.apache.org/repos/asf/cordova-js.git
    
  2. Create a new javascript file under lib/bada/plugin/bada/ and name it HelloWorld.js. Add the following content:

     function HelloWorld() {
     }
    
     HelloWorld.prototype.printHello = function(success, fail, arg) {
         alert(Osp.Core.StringHelper('Hello %1', arg[0]));
     }
    
     module.exports = new HelloWorld();
    
  3. Add a link to your newly created plugin in lib/bada/platform.js under the objects property:

     objects: {
         ...
         HelloWorld: {
             'cordova/plugin/bada/HelloWorld' 
         },
         ...
     }
     ...
    
  4. Update the plugin list under lib/bada/exec.js to include your plugin

     var plugins = {
         ...
         "HelloWorld": require('cordova/plugin/bada/HelloWorld')
     };
    
  5. Now you can write your user-facing javascript however you like but remember that in order for your plugin to execute you need to call the following method

     exec(success, fail, 'HelloWorld', 'printHello', ['Jackson!']);
    

    success is the success callback that gets executed when the plugin succeeds fail is the failure callback that gets executed if the plugin fails 'HelloWorld' is the name of your plugin 'printHello' is your plugin action Finally, the last argument is your plugin parameters (if any).

  6. Run the following command to generate the new common javascript (make sure you have the jake npm module installed)

     jake
    
  7. Copy the newly generated javascript under pkg/cordova.bada.js to your Bada project under Res/js

  8. That is it! You can now add new Bada plugins and implement the many features that are not currently supported by Cordova Bada.