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
Trusted Contributor
Posts: 103
Registered: ‎03-31-2011
My Device: Curve 9330
My Carrier: Verizon

Push Icon Change. Is this right?

Im trying to change the icon when new push data is recieved.  Why I find info on it , I cannot find any direct examples. So Am I doing this right?   I run this code in the onload of my home(index) screen function.

 

   

// Push
                var port = 100;
                
                function subscribe() {
                    //open the listener to listen if there is pushed data coming through
                    blackberry.push.openPushListener(handleReturnData, port);
                    //alert("push listening has started");
                }

                //handleReturnData - the function to call for the event of pushed data coming through
                //port - the port to listen on
                function handleReturnData(data) {
                    if (data != null) {
                        blackberry.app.setHomeScreenIcon('imgs/iShopIconNew.png');
                        var text = blackberry.utils.blobToString(data.payload);
                        document.getElementById("txtHint").innerHTML=text;
                        setCookie("newinfo",text,365);
                        //alert("text recieved from push: " + text);
                    } else {
                        //alert("No data from the push");
                        setCookie("newinfo","0",365);
                     }
                }

                //function unsubscribe() {
                    //stop listening for pushed data, a clean up step
                  //  blackberry.push.closePushListener(port);
                    //alert("Push listening has stopped");

 

Developer
Posts: 34
Registered: ‎07-14-2011
My Device: BlackBerry Curve 9300
My Carrier: Orange

Re: Push Icon Change. Is this right?

In the version 2.1 of webworks the push API has changed. You are using the push api of the version 2.0 so I recommend you strongly to use the new methods of the push api.


Here is the documentation


http://www.blackberry.com/developers/docs/webworks/api/blackberry.push.html

Trusted Contributor
Posts: 103
Registered: ‎03-31-2011
My Device: Curve 9330
My Carrier: Verizon

Re: Push Icon Change. Is this right?

Ok I see the diff in the openpushListener but am I doing the Icon change right?
Developer
Posts: 34
Registered: ‎07-14-2011
My Device: BlackBerry Curve 9300
My Carrier: Orange

Re: Push Icon Change. Is this right?

[ Edited ]

The path of your icon is wrong. You must put the prefix "local:///" before the path of the icon.

Here in the documentation talk more about that:

http://www.blackberry.com/developers/docs/webworks/api/blackberry.app.html#.setHomeScreenIcon

 

In the case that your icon is inside your project directory (a local resource) then you must use:

 

blackberry.app.setHomeScreenIcon('local:///imgs/iShopIconNew.png');

 

If your image icon is inside the SDCard (an external resource) then you must put:

 

blackberry.app.setHomeScreenIcon('file:///SDCard/imgs/iShopIconNew.png');

Trusted Contributor
Posts: 103
Registered: ‎03-31-2011
My Device: Curve 9330
My Carrier: Verizon

Re: Push Icon Change. Is this right?

[ Edited ]

Ok so if I were to just put  blackberry.app.setHomeScreenIcon('local:///imgs/iShopIconNew.png');  in the onLoad function  of the index page the Icon should change when I run the app. I should be able to see the new Icon when I exit the app.  Correct?   This would be a good way to test it? 

Developer
Posts: 34
Registered: ‎07-14-2011
My Device: BlackBerry Curve 9300
My Carrier: Orange

Re: Push Icon Change. Is this right?

When the onload event is triggered the new icon is going to appear. But when you finish the application the new icon is going to stay (the old icon is not going to get back).
Trusted Contributor
Posts: 103
Registered: ‎03-31-2011
My Device: Curve 9330
My Carrier: Verizon

Re: Push Icon Change. Is this right?

Correct.  That was just to see it in action.   Forgive me I feel like I'm in java 101 hehe.  But all this goes into the pages onload function right?  You don't put it in script and then call "subscribe();" and "handleReturnData(data);"  in your onLoad function?