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.
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
- In index.html:
- The plug-in's JavaScript implementation is referenced in the
head
element
<script src="js/local-notification.js"></script>
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.
In local-notification.js:
- Add at the top:
cordova.define("LocalNotification", function(require, exports, module) {
- Add at the bottom:
});
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…