Android Attributes

Attributes can be used to customize the content of a message. The replacement is done using a subset of the mustache format:

{{ user.attribute | default }}
note

default is optional. For example, using {{ user.attribute }} will be replace with an empty string if attribute is not set.

For example, you can set a user's name in your app with the code below:

OpenBack.setAttribute("name", "Bob");

Then in the dashboard, you can use this attribute in your message. The message below will say Hey Bob!, but will fallback to Hey player! if no name is found.

Hey {{ user.name | player }}!

Setting an attribute value

An Attribute value can be any type that can be JSONified (string, number, array, pojo). You can set any number of attributes but during the application runtime, they can take extra memory space.

OpenBack.setAttribute("name", "Bob");
OpenBack.setAttribute("color", 0xE74B99);
OpenBack.setAttribute("wallet", 235.4);

Clearing an attribute value

OpenBack.setAttribute("wallet", null);
// Clear all the attributes
OpenBack.removeAllAttributes();

Getting an attribute value

// Get the Object value of attribute "name"
// If value is null, attribute "name" is not set
Object value = OpenBack.getAttribute("name");
// Get the string value of attribute "name"
String value = OpenBack.getAttributeAsString("name");
// Get the long value of attribute "color" - defaults to 0
long value = OpenBack.getAttributeAsLong("color");
// Get the double value of attribute "wallet" - defaults to 0.0
double value = OpenBack.getAttributeAsDouble("wallet");

Pre-defined Attributes

The OpenBack SDK comes with pre-defined attributes that you can use to personalize the content of a notification. Simply store the appropriate user information within these attributes. The list of pre-defined attributes can be seen below:

AttributeExample Usage
AdvertisingId{{ user.advertisingId }}