04-18-2012 01:23 PM
I had this question in another topic but I think it's more appropriate to make a new message about it.
My listener file listener.htm consists of:
<html> <head> <script type="text/javascript" src="js/listener.js"></script> </head> <body onload="testBanner()"> </body> </html>
and my testBanner() function is
function testBanner()
{
blackberry.app.showBannerIndicator('images/icon.pn g', 1);
blackberry.app.setHomeScreenName('New Name');
}config.xml content portion:
<content src="index.htm" >
<rim:background src="listener.htm" runOnStartup="true" />
</content>
Out of all this, I am not getting an indicator to pop up when I install the app, when I turn off and on (& remove battery) or when I launch it. My icon which is located in the images folder is 31px by 31px. I have tried using all three of the following to call function:
blackberry.app.showBannerIndicator('local:///image s/icon.png', 1);
blackberry.app.showBannerIndicator('images/icon.pn g', 1);
blackberry.app.showBannerIndicator('../images/icon .png', 1);When I remove the battery and turn on the phone, I hold down menu and see my application icon showing. Does anyone know why the notification isn't happening?
04-18-2012 02:26 PM - edited 04-18-2012 02:27 PM
Hi there,
Have you included the following <feature> within your config.xml?
<feature id="blackberry.app" />
I would also recommend wrapping your testBanner() method in a try/catch, as well as inserting a few alert calls to ensure everything is firing.
function testBanner()
{
try {
alert("Calling showBannderIndicator.");
blackberry.app.showBannerIndicator('images/icon.pn g', 1);
alert("Calling setHomeScreenName.");
blackberry.app.setHomeScreenName('New Name');
} catch (err) {
alert("Something went wrong. Specifically this: " + err);
}
}
Just to confirm, you are testing this on a smartphone correct?
Erik Oros
BlackBerry Development Advisor
04-18-2012 04:27 PM
Hey thank you I didn't have
<feature id="blackberry.app" />
inside my <feature> tag, now I am able to bring up the icon on the home screen. I am not seeing the alerts however, I'm not sure if this is possible from the home screen? And yes I am testing on a live device - blackberry torch 9810. I think I've asked this before somewhere but I'm also trying to get a message to pop up beside the icon on the home screen something like "New Notification". Is this possible or does the feature not exist?
Also I would need to share the count variable with the listener and the index files (background and foreground), can this simply be done by having a local storage variable even though the variables would be in two different javascript files?
Again thanks for your help
04-20-2012 05:41 PM
Hi there,
Calls to alert will not be displayed if your application is not in the foreground. Generally I workaround this by creating a logging <div> alongside a function like so:
function log(text) {
var div = document.createElement("div");
div.innerHTML = text;
document.querySelector("#log").appendChild(div);
}
That way, when I go back into my application any messages are listed there.
Through WebWorks extensions (i.e. tying down into Java on the Smartphone) you can display a popup dialog when the application is not in the foreground. There is a thread on this here that walks through the process of building the extension:
With respect to sharing a variable between pages. Any time you load a new page, you will create a new instance of the DOM, and wipe out any previous variables you had stored. Localstorage should be able to get you around this. Lately it's been becoming fairly popular as well to simply have one HTML page, and load sections in asynchronously. This is a common practice in bbui.js.
Let me know if anything doesn't make sense or if I missed anything.
Erik Oros
BlackBerry Development Advisor