I have been unsuccessfully trying to implement notification click (tap) handlers for my Firefox OS app.
API documentation on the Notification object is here: https://developer.mozilla.org/en-US/docs/Web/API/notification
In my app, I have an function that will launch the phone's browser when a notification is tapped and navigate to a URL:
notification.onclick = function(){
var navURL = new MozActivity(
{
name: "view",
data: {
type: "url",
url: "https://google.com"
}
});
console.log("Notification tapped");
};
When the user is viewing the app and taps a notification, my app will launch the browser and navigate to Google's homepage accordingly.
However, if my app is running in the background, nothing happens when the notification is tapped. The console will still print the "Notification tapped" message (so apparently the event handler is called), but the browser does not launch. Go back into the app and everything works fine again.
Is there a way to get the browser to launch even when my app is in the background?
EDIT: ALTERNATIVE SOLUTION
Is it possible to bring my app back up into the foreground when the notification is tapped?
notification.onclick = function(){
var navURL = new MozActivity(
{
name: "view",
data: {
type: "url",
url: "https://google.com"
}
});
navUrl.onsuccess = function () {
// fired if appication is running foreground
}
navUrl.onerror = function () {
// fired if application is running background
navigator.mozApps.getSelf().onsuccess = function (){
this.result.launch();
}
}
};
As already said before this should work