BuzzBox
Android Notifications and Analytics
 
 


Notification API

BuzzBox SDK provides a simple API to create a notification from your Task

Features

In your Task class (I.e. class MyTask implements Task)

@Override
public TaskResult doWork(ContextWrapper ctx) {
            
    // write here your code
    
    //1. create a TaskResult                
    TaskResult res = new TaskResult();
    
    //2. create a Notification
    NotificationMessage notification = new NotificationMessage(
    	"New Email", 
    	"You have a new message from Lucy");
    
    //3. set details
    notification.setNotificationSettings(false, false, true); // sound, vibrate, led
    notification.setNotificationClickIntentClass(YourMainActivity.class);
    notification.setBgColor("#55ff0000");  // <-- set a custom background color
    notification.setFlagResource(R.drawable.tag_blue); // <-- set a custom flag image

    //4. add the notification to the result

    res.addMessage( notification );    
    return res;
}

To pass parameters to your activity from the notification, set a custom Bundle for the Intent. For example:

	Bundle b = new Bundle();
	b.putString("param", "value");
	notification..setNotificationClickIntentBundle(b));		

Alternatively you can fully customize the Intent that will be sent when the user click on the Notification setting the Intent in the NotificationMessage. I.e. you want a message to be sent when the user click on the notification, use:

	final Intent i = new Intent(Intent.ACTION_SEND);
	i.setType("text/html");
	i.putExtra(Intent.EXTRA_EMAIL, new String[]{"emailto@gmail.com"});
	i.putExtra(Intent.EXTRA_SUBJECT, "subject");
	i.putExtra(Intent.EXTRA_TEXT, "text");
	notification.setIntent(i);

Custom Notification Message

Since version 0.5.4

BuzzBox Notification Api adds 2 new features to Android Notifications


Set up

You must add buzzbox_notification.xml to your layout directory. It describe the Custom Notification UI. Feel free to personalize it even more if you need it.

Code Usage


notification.setBgColor("#55ff0000");  // <-- set a custom background color
notification.setFlagResource(R.drawable.tag_blue); // <-- set a custom flag image

Resources

You can use any image as a flag icon. The icon can be set programmatically through the Notification API. You can use our free images if you like them:

Grouping Notifications

If you plan to use the Notification History, you can organize Notification into groups.
For example, you have a Task that check for new incoming messages. If the Task finds 3 new messages you can notify the user with a notification that says "You have 3 new messages" or you can create 3 distinct notifications, one for each message. If you group the 3 notifications together, the user will be notified just once but the 3 individual messages will be available in the Notification History.
Use NotificationMessage::addNotificationElement to group messages.

NotificationMessage group = new NotificationMessage(
        "mail",
        "You have 2 messages",
        "You have 2 new messages",
        "Don't forget to open My App", 
        0);
group.setTime(now);

NotificationMessage group1 = new NotificationMessage(
        "mail",
        "Hello",
        "Hello",
        "How are you doing?", 
        0);
group1.setTime(now-1000);
group.addNotificationElement(group1);

NotificationMessage group2 = new NotificationMessage(
        "mail",
        "What's up?",
        "What's up?",
        "Hey, what's up?", 
        0);
group2.setTime(now-2000);
group.addNotificationElement(group2);

res.addMessage(group);

If you want to support this feature, we recomment to always group messages. If you have just 1 message, the Notification Api will not show the group message.

 


BuzzBox Inc. 2010-2011