Using katzer local notification in IBM Worklight
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
- res\xml folder:
- Contains config.xml; see at the bottom for the plug-in feature declaration
- Contains config.xml; see at the bottom for the plug-in feature declaration
- AndroidManifest.xml:
- In index.html:
- The plug-in's JavaScript implementation is referenced in the
head
element<script src="js/local-notification.js"></script>
- The plug-in's JavaScript implementation is referenced in the
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:
});
- Add at the top:
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.
How can i create local Notification in worklight
iOS's Local Notifications feature does not have built-in support in Worklight.
One way to add Local Notifications support is by extending your application using a Cordova plug-in, which will allow you to run Native code.
This means that you will natively implement it by following Apple's APIs: to schedule the notification in the app and to then receive a notification locally via the OS, that will in turn allow you to open the app and execute an optional callback, etc...
You could either write a custom Cordova plug-in of your own,
Or find existing plug-ins on the web.
When adding an existing Cordova plug-in to Worklight (depending on your version of Worklight and version of Cordova), the instructions to do so are a bit different at this time.
This video demonstrates one instance of how to do add an existing Cordova plug-in: Integrating Cordova plugins into Worklight applications
How to show local notification - Worklight
If you are in fact referring to Location Notifications, see these questions:
- Using katzer local notification in IBM Worklight
How can i create local Notification in worklight
It would've helped if you mentioned which environments you are aiming to, but with some tinkering the above should work in both Android and iOS.
If when you say "alert" you actually mean a dialog...
You can use Cordova's
pause
event, like the below.
Displaying analert()
is not professional looking IMO. Anyway, you can replace the belowWL.SimpleDialog
with an alert...common\js\main.js
function wlCommonInit(){
document.addEventListener("pause", showDialog, false);
}
function showDialog() {
WL.SimpleDialog.show(
"My Dialog", "My Text",
[{text: "My Button", handler: function() { }}]
);
}There is no "rendering" when the application is not in the foreground, so I think the above is the best you're going to get.
When sending the application to the background, display an alert. This way when you then bring the application back to the foreground, a dialog will be displayed.
Sending Push notification from client - Worklight
You can invoke a procedure in the client side. I tried to invoke in the client side with httpAdapter and its working.
If the notification doesn't need to come from the server, you can also create a service that will run in the background and show a dialogbox once it enters the geofence.
Related Topics
Is There a Workaround for The Android Browser Bug with CSS-Position and Clickable Areas
Android Imageview Change Tint to Simulate Button Click
Android: I Want Use My Custom Font with Webviewb
How to Keep The Oauth Consumer Secret Safe, and How to React When It's Compromised
How to Access Adb in Os X Through Terminal, "Command Not Found"
Get Android .Apk File Versionname or Versioncode Without Installing APK
How to Show a Preview of a Recyclerview's Contents in The Android Studio Editor
How to Set The Font Style to Bold, Italic and Underlined in an Android Textview
Do Android Support Multiple Languages
How Open New Activity Clicking an Item in Listview
A Pre-Populated Database Does Not Work at API 28 Throws "No Such Table" Exception
Android Layout with Square Buttons
Android/Java: How to Delay Return in a Method
Mysterious Stacktrace in Android Developer Console (Bitmap Size Exceeds 32Bits)