Using katzer local notification in IBM Worklight

前端 未结 1 492
故里飘歌
故里飘歌 2020-11-30 16:08

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 Workli

相关标签:
1条回答
  • 2020-11-30 16:26

    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

    0 讨论(0)
提交回复
热议问题