The fourth part of this series of posts will cover Notifications. When you are a user of GMail and using Chrome, you probably are familiar with those little boxes that popup when you've got new mail. Those type of notifications you can create in your APEX application as well - using HTML5!
Alas, at this moment, these type of notifications only work in Chrome. In Firefox you can add this extension so it'll work in that browser as well. The other ones will follow - sooner or later...
You can also use this plugin that mimics this feature - to be safe on every platform, but that one will appear in your browser, so that's not a desktop notification.
But how do you create a real desktop notification?
As usual with HTML5, you just need a few lines of code. The code below is executed in a Dynamic Action when a button is pressed:
function RequestPermission (callback) {
window.webkitNotifications.requestPermission(callback);
}
function showNotification(){
if (window.webkitNotifications){
if (window.webkitNotifications.checkPermission() > 0) {
RequestPermission(showNotification);
}
else {
window.webkitNotifications.createNotification(
"#APP_IMAGES#HTML5.jpg", //Put link to your icon here
"Notification",
"Now you are notified!").show();
}
}
else
{ alert('Sorry, you have to switch to another browser to use notifications - or use the other button ;-)');
}
}
//Run:
showNotification();
Alas, at this moment, these type of notifications only work in Chrome. In Firefox you can add this extension so it'll work in that browser as well. The other ones will follow - sooner or later...
You can also use this plugin that mimics this feature - to be safe on every platform, but that one will appear in your browser, so that's not a desktop notification.
But how do you create a real desktop notification?
As usual with HTML5, you just need a few lines of code. The code below is executed in a Dynamic Action when a button is pressed:
function RequestPermission (callback) {
window.webkitNotifications.requestPermission(callback);
}
function showNotification(){
if (window.webkitNotifications){
if (window.webkitNotifications.checkPermission() > 0) {
RequestPermission(showNotification);
}
else {
window.webkitNotifications.createNotification(
"#APP_IMAGES#HTML5.jpg", //Put link to your icon here
"Notification",
"Now you are notified!").show();
}
}
else
{ alert('Sorry, you have to switch to another browser to use notifications - or use the other button ;-)');
}
}
//Run:
showNotification();
Just like geoLocations, the browser has to ask the user for permission to use Desktop Notifications (for a domain). Once the permission has been granted you can call the "show()" method, containing an image, the title and the actual message. Easy and cool, huh!
And you can even get completely wild by creating notifications that contain HTML or adding event listeners to your notifications - for instance doing something when the notification is closed. See this for some more examples.
See the working APEX example on : http://apex.oracle.com/pls/apex/f?p=22115:NOTIFICATIONS.
Comments
Can you please, make your app available for us to download for better understanding ...
Another thing, on the link you referenced - for more examples - there is plus sign on the right hand that we can use to scroll down to specific section on the page. How can we apply this on APEX to scroll down into specific region on the page..
Best Regards,
Fateh
Can we use this notification to send a notification to a specific apex user ??
Best Regards,
Fateh
Imagine you create a table with a TO_USER and MESSAGE column. Then you can conditionally load a region containing with the notification on Page 0 - so when the user refreshes or changes the page he gets the notification.
If you want to send a user a notification even without a refresh/pagechange, you should check out Websockets....
HTH
Roel