Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

android - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
    • resxml 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 projectassetswwwdefaultjsworklightcordova_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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...