Using katzer local notification in IBM Worklight

I want to use this cordova plugin at https://github.com/katzer/cordova-plugin-local-notifications

How to go about integrating this plugin with my existing IBM Worklight project? I have trying various methods to integrate it without any result.

I am getting this error currently from the logcat:

02-24 11:15:03.035: D/CordovaLog(2439): file:///data/data/com.iCareApp/files/www/default/index.html: Line 17 : Uncaught TypeError: Cannot read property 'notification' of undefined

Or is there any other easier alternatives to get this done? Basically i want to be able to schedule local notification on the device at specific times from the data stored in my application


Solution 1:

I got this to work by following the below.

Demo project: https://www.dropbox.com/s/58urdluauc8u3l1/AndroidLocalNotifications.zip

Because Worklight does not support Cordova's Plugman to easily "install" Cordova v3 plug-ins, some manual labor is required to get it all set-up properly... blachs.

Note the appName , it is used throughout the process for plug-in declarations. If you use a different name for in your app, you will need to update the values accordingly with yours.

  1. Pay attention to the nativeResources folder, where I've placed the files I edited:

    • AndroidManifest.xml:
      • In it I added the required permission, receivers, activities
    • libs folder:
      • Contains required .jar file by the plug-in
    • src folder:
      • Contains the plug-in's Java classes
      • In them I've edited the plug-in import declaration
    • res\xml folder:
      • Contains config.xml; see at the bottom for the plug-in feature declaration

  2. In index.html:
    • The plug-in's JavaScript implementation is referenced in the head element
      <script src="js/local-notification.js"></script>

  3. In main.js:

    function wlCommonInit(){
        window.plugin.notification.local.add({ message: 'this is a local notification' });
    }
    

    The above will send a local notification immediately after the application's launch.
    In the plug-in's homepage you can read more about the possible notification options.

  4. In local-notification.js:

    • Add at the top:
      cordova.define("LocalNotification", function(require, exports, module) {

    • Add at the bottom:
      });

  5. In the generated Android project\assets\www\default\js\worklight\cordova_plugins.js, add:

    ,
    {
        "file": "../js/local-notification.js",
        "id": "LocalNotification",
        "clobbers": [
            "plugin.notification.local"
        ] 
    } 
    

    Note that re-building the Worklight project will overwrite this file, and thus your changes in it will be gone... you'll need to repeat this step after every build.

    There is no good way that I could find to preserve changes to this file between Worklight Studio builds.

enter image description here