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: 100
Registered: ‎01-13-2012
My Device: Simulator - 9800
My Carrier: Simulator

Notification Trigger

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.png', 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:///images/icon.png', 1);
	blackberry.app.showBannerIndicator('images/icon.png', 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?

Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Notification Trigger

[ Edited ]

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.png', 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


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.
Trusted Contributor
Posts: 100
Registered: ‎01-13-2012
My Device: Simulator - 9800
My Carrier: Simulator

Re: Notification Trigger

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

 

 

 

 

Highlighted
Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Notification Trigger

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:

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/HTML5-App-Show-Pop-Up-Window-whe...

 

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


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.