Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying multiline notifications

I just started playing around with Mozilla Jetpack, and I love it so far. I wrote a little code that displays an icon in the statusbar that, when clicked, brings up a notification:

var myTitle = 'Hello World!';
var line1 = 'I am the very model of a modern Major-General,';
var line2 = 'I\'ve information vegetable, animal, and mineral,';
var line3 = 'I know the kings of England, and I quote the fights historical,';
var line4 = 'From Marathon to Waterloo, in order categorical.';
var myBody = line1 + ' ' + line2 + ' ' + line3 + ' ' + line4;
var myIcon = 'http://www.stackoverflow.com/favicon.ico';

jetpack.statusBar.append({
  html: '<img src="' + myIcon + '">',
  width: 16,
  onReady: function(doc) {
    $(doc).find("img").click(function() {
      jetpack.notifications.show({title: myTitle, body: myBody, icon: myIcon});
    });
  }
});

Because the text is very long in this example, the notification looks like this:

Jetpack Notification http://img33.imageshack.us/img33/7113/jetpack.png

I want to split the text of the notification onto four different lines when they are displayed so the notification box is taller and narrower. How do I go about doing this?

Edit 1 (Thanks to Rudd Zwolinski):

I tried, but this does not help:

var myBody = line1 + '\n' + line2 + '\n' + line3 + '\n' + line4;

Edit 2 (Thanks to Ólafur Waage):

This does not help either:

var myBody = line1 + '<br />' + line2 + '<br />' + line3 + '<br />' + line4;

Edit 3 (Thanks to Matt):

Even this does not help:

var myBody = line1 + "\n" + line2 + "\n" + line3 + "\n" + line4;
like image 994
eleven81 Avatar asked May 22 '09 15:05

eleven81


People also ask

How do I show multiple notifications on Android?

Set the unique id to let Notification Manager knows this is a another notification instead of same notification. If you use the same unique Id for each notification, the Notification Manager will assume that is same notification and would replace the previous notification.

How do I get full screen notifications on Android?

1. Notify while the app on the foreground. In order to show a full-screen intent, we need to first build the notification and set the full-screen intent to the notification. To build the intent we need a pending intent, which can be achieved using PendingIntent.


1 Answers

Unfortunately, the alert created doesn't allow new lines for the toast popup in Windows. According to the Jetpack API:

Eventually, this object will be the end-all be-all of easy communication with your users. Notification bars, transparent messages, Growls, doorknob messages, and so forth will all go through here. For now, it just has simple notifications.

As shown in the source code, the jetpack.notifications.show method makes a call to the Mozilla nsIAlertsService, which doesn't allow multiple lines for the Windows toast popups.

The upside is that the API indicates that you'll have much more control over alerts in the future, but for the pre-release version you'll have to keep your notification text down to a minimum.

like image 127
Rudd Zwolinski Avatar answered Sep 18 '22 16:09

Rudd Zwolinski