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
Developer
Posts: 185
Registered: ‎08-17-2008
My Device: Red BlackBerry Z10
My Carrier: Vodafone
Accepted Solution

Complet Widget Push example code?

Some body knows if exist some complet Widgets Push example code, with subscribe, unsuscribe, background, BlackBerry Push Service....?

 

I am looking for and only found parts, not a complet example.

 

Thanks in advance

Josep Maria
Developer
Posts: 482
Registered: ‎10-24-2008
My Device: 9300
My Carrier: AT&T

Re: Complet Widget Push example code?

Not a full example, but here is my JavaScript for the push functionality.

 

 

 

var port = 201;
...
function subscribe() {
   blackberry.push.openPushListener(handleReturnData,port);
}

function handleReturnData(data) {
   var wasBackground = false;
   if (!blackberry.app.isForeground) {
      wasBackground=true;
      blackberry.app.requestForeground();
   }
   if (data!==null) {
      var text = blackberry.utils.blobToString(data.payload);
      ...
      //do some work with text
      ...
   }

   if (wasBackground) 
      blackberry.app.requestBackground();
}

function unsubscribe() {
   blackberry.push.closePushListener(port);
}

 

also...

 

 

function init() {
   ...
   blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK,sendToBackground);
   blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_ENDCALL,sendToBackground);
   blackberry.app.event.onExit(unsubscribe);
}

function sendToBackground() {
   blackberry.app.requestBackground();
}

 

stick that in a js file and call init() and subscribe() in the "onLoad" of your HTML page... should get you close to a working example. Throws some alerts in the handeReturnedData function to see what you pushed.

 

 

 

_________________________________________
www.jasonmace.com/blackberry
Developer
Posts: 185
Registered: ‎08-17-2008
My Device: Red BlackBerry Z10
My Carrier: Vodafone

Re: Complet Widget Push example code?

Hi Jason!!! Thanks a lot for the code!!

Josep Maria