Hello guys,
When user click a item in Notification bar on FFOS device, the FFOS will open a specific App to handle the item.
For example, the user click a SMS notification, FFOS should open the SMS App and switch to the specific message thread page by phone number.
As developers use the createNotification function in navigator.mozNotification to create a notification,
but there is no sensible way to pass a data to the handler function in navigator.mozSetMessageHandler.
The spec of createNotification function:
https://developer.mozilla.org/en-US/docs/DOM/navigator.mozNotification
notification createNotification(
in DOMString title,
in DOMString description,
in DOMString iconURL Optional
);
You could see the following code in SMS app in Gaia project.
https://github.com/mozilla-b2g/gaia/blob/master/apps/sms/js/activity_handler.js#L175
window.navigator.mozSetMessageHandler('notification',
function notificationClick(message) {
if (!message.clicked) {
return;
}
navigator.mozApps.getSelf().onsuccess = function(evt) {
var app = evt.target.result;
app.launch();
// Getting back the number form the icon URL
var notificationType = message.imageURL.split('?')[1];
// Case regular 'sms-received'
if (notificationType == 'sms-received') {
var number = message.imageURL.split('?')[2];
showThreadFromSystemMessage(number);
return;
}
var number = message.title;
// Class 0 message
var messageBody = number + '\n' + message.body;
alert(messageBody);
};
});
}
In the notificationClick function, the message object could have four attributes:
1. clicked
2. title
3. description
4. imageURL
Because there is no attribute for passing data, the SMS app use the imageURL attribute to store data for passing to the mozSetMessageHandler.
We could see the code in GitHub page
https://github.com/mozilla-b2g/gaia/blob/master/apps/sms/js/activity_handler.js#L153.
It's a hack way to pass data to the mozSetMessageHandler.
The hack way is also used in 'Bug 855814 - Calendar: Notification: Tapping doesn't always launch app and show event'.
http://bugzil.la/855814
So my proposal is that we should add a new parameter 'message' for passing data to the mozSetMessageHandler.
Is that possible, or anyone have other ideas for this?
Thanks. :)