2

is there a way to direct the user to another html page upon opening a push notification?

Thank you in advanced.

AWSSET
  • 397
  • 1
  • 4
  • 12

1 Answers1

2

If you will take a look at the sample Worklight project for Push Notifications, you can see the following in common\js\main.js:

function pushNotificationReceived(props, payload) {
    alert("pushNotificationReceived invoked");
    alert("props :: " + JSON.stringify(props));
    alert("payload :: " + JSON.stringify(payload));
}

This function tells the application to display 3 alerts, telling us that:

  • a push notification was received
  • its props
  • its payload

Instead of the above, or in addition, you could - depending on your method of multi-page navigation in your app - to navigate to another "page".

You can take a look at:


Here is a small example.
These are the modifications I did to the Push Notifications sample project:

common\css\main.css
Added a successfulPush ID

#AppBody, #AuthBody, #successfulPush {
    margin: 0 auto;
    background-color: #ccc;
    overflow: hidden;
    overflow-y: auto;
}

common\index.html
Added an additional DIV:

<div id="successfulPush" style="display:none">
    <div class="wrapper">
        <h2>Notification received</h2>
        <button id="back" >back to application</button>
        <p id="pushContents"></p>
    </div>  
</div>

common\js\main.js
Modified the following function:

function pushNotificationReceived(props, payload) {     
    $("#AppBody").hide();
    $("#successfulPush").show();
    $("#pushContents").html(
        "<b>Notification contents:</b><br>" +
         "<b>Payload:</b> " + JSON.stringify(payload) + "<br>" + 
         "<b>Props:</b> " + JSON.stringify(props)
    );
}

Also binding the 'back' button in wlCommonInit:

$("#back").bind("click", function() {
    $("#successfulPush").hide();
    $("#AppBody").show();
});

The end result
After a push is received and you tap the notification in the notification bar, the app opens and you see the successfulPush DIV. There you have a button to return you to the AppBody DIV. Works just fine.

As explained, this is only one possible approach. You can do whatever you want...
enter image description here

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • i think this function is immediately called once a notification is received? But i want to open a new page only when the user clicks on the notification. – AWSSET Sep 02 '14 at 01:10
  • I have tried this and it does not call the function upon clicking the notification. Will try it again. thank you. – AWSSET Sep 02 '14 at 03:40
  • @AWSSET, this is working just fine. See my updated answer for a small example. – Idan Adar Sep 02 '14 at 04:27
  • Hi. sorry for the late reply. I used the invoke adapter procedure and end up receiving the alerts triggered by the pushnotificationReceived function, However, i did not received the push notification itself. I triggered around 15 times and only received 1 push notification – AWSSET Sep 03 '14 at 08:43
  • What are you talking about. If you received the alerts, this means you've received the notification! The alerts are the outcome of receiving the notification. You are asking poorly worded questions, I cannot help you anymore like this. – Idan Adar Sep 03 '14 at 08:44
  • I did not received any push notifications in my android device. i know it seems weird but I invoked the adapter procedure and only received the alerts. Do i need to add any permissions in my androidmanifest? or do i need to change any settings? – AWSSET Sep 03 '14 at 08:51
  • If your application is open when you send the notification, you will not see the notification in the notification bar... put the app in the background or quit it and then send the notification – Idan Adar Sep 03 '14 at 08:51
  • @IdanAdar how to implement the same thing on worklight application with angularJS App. as i have multiple .HTML pages. – Priyank Sep 09 '15 at 13:41
  • @IdanAdar Above implementation is good for application which have full code in the same file. but in my case i have different .html file in angularJs. so can you explain how to implement in my app. Thanks in advance :) – Priyank Sep 09 '15 at 13:43