Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Regular Contributor
iruka
Posts: 79
Registered: ‎09-17-2012
My Device: Torch 9800
My Carrier: DiGi
Accepted Solution

BB10 - Customizing Push Notification

Hello all. Recently we are testing out an app with our client. The app will receive push notification when there is new claim being created so the user can be notified and then they can approve/reject the claim.

 

When the push comes in, there will be asterisk on app icon, minimized app and also a message will be sent to the Hub. But feedback from users during testing, they would be prefer to 

 

1. Have the asterisk on the app icon/minimized app but not have the message being sent to the Hub

2. If a user clicks on a message to view in the Hub, it will delete the current and subsequent message in the Hub

 

Is it possible to be done?

 

For no 1, I have tried not to call Notification in app.textConversionCallback so there will be no message in the Hub but this prevents the asterisk from being displayed on the app icon. 

 

app.parsePayload = function (){
    try{
        if (app.pushService !== null){
            var pushPayload = app.pushService.extractPushPayload(app.onInvokedInfo);
            app.blobToText(pushPayload.data, "UTF-8", app.textConversionCallback);
            app.onInvokedInfo = null;
        }
    } catch (err) {
     alert("Was unable to parse the invoke request.");
  }
};

app.blobToText = function (blob, encoding, callback) {
    var reader = new FileReader();
    reader.onload = function(evt) {
        // No errors, get the result and call the callback
        callback(evt.target.result);
    };

    reader.onerror = function(evt) {
        app.debug("Error converting Blob to string: " + evt.target.error);
    };
    reader.readAsText(blob, encoding);
};

app.textConversionCallback = function(str) {
    //try to disable this but push is not working
    //notify.hub(str);
};

var notify = {};

// Add a notification in the Hub
notify.hub = function(str) {
  var mclaim = JSON.parse(str)
  {
    if(mclaim.empno)
	{
	  var pushCount = parseInt(mclaim.workqcnt);
	  if((pushCount > 0) && (pushCount > 1))
	  {
	    var title = "Pending Claims Notification";
	    var isAre = "are";
		var claim = "claims";
	  }
	  if((pushCount > 0) && (pushCount == 1))
	  {
	    var title = "Pending Claim Notification";
	    var isAre = "is";
		var claim = "claim";
	  }
	  var content = "There "+isAre+" "+parseInt(pushCount)+" "+claim+" pending for approval.";
	  new Notification(title, {body: content});
	}
  }
};

As for no 2, is there a function the perform the delete action?

 

Any advice/suggestion will be greatly appreciated. 

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,523
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: BB10 - Customizing Push Notification

The update icon on the application is directly tied to the HTML5 Notification; there is no way to trigger the icon unless you are using the HTML5 Notification.

You could potentially write an extension to access the following Native API to set the badge (i.e. update icon) for the app:
https://developer.blackberry.com/native/reference/core/com.qnx.doc.bps.lib_ref/com.qnx.doc.bps.lib_r...

For deleting notifications in the Hub, you could either:
1) Create all HTML5 Notifications with the same tag; this will force only one notification to ever exist in the Hub, with the most recent notification overwriting previous notifications; or
2) Keep track of all active notification tags and use the remove function to delete the desired notifications.
https://developer.blackberry.com/html5/apis/notification.html#.remove

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Regular Contributor
iruka
Posts: 79
Registered: ‎09-17-2012
My Device: Torch 9800
My Carrier: DiGi

Re: BB10 - Customizing Push Notification

Thanks for the advice. Currently I'm trying to to tagged them together. 

 

Can we know if a message in Notification Hub has been read or not? I'm trying to reset the counter in the message notification so that let's say there's 10 pending claims message counter in the message notification, user has read the message but not deleted it or invoke the app, so the message is there in the Hub. 

 

And if there incoming push with 2 pending claims, the message will be increased to 12, and I'm trying to reset the pending claim counter. If the app is not being invoked, the counter cannot be reset so I was wondering if there API or function in WebWorks that could detect if a message in the Notification has been read or not.

 

 

 

 

 

 

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,523
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: BB10 - Customizing Push Notification

I'm not aware of any APIs to see when a Notification is read, only opened (i.e. invoked.)
https://developer.blackberry.com/html5/apis/blackberry.invoked.html#.event:invoked

However this won't exactly help your situation since somebody can read the notification without "opening" it (i.e. triggering an invoke.)

This sounds like it may be a good feature request to submit through the Developer Issue Tracker.

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.