Skip to content

Documentation Sections

OpenBack Android SDK version 4+

import com.openback.OpenBack;

All fields ands methods are for the OpenBack class.

Configuration

setAppCode

public static void setAppCode(@Nullable String appCode)

Set the OpenBack application code.
You can also provide the app code using the meta-data in your application section:
<meta-data android:name="com.openback.APP_CODE" android:value="YOUR_APP_CODE" />

Parameters
appCode String The OpenBack app code for your application.
Setting the app code with this method will override the meta-data. The app code will be stored. Setting it to null will fallback to the meta-data.

getAppCode

@Nullable
public static String getAppCode()

Get the current OpenBack app code used

setAutoStart

public static void setAutoStart(boolean autoStart)

Turn on/off the auto-start feature.
You can also enable auto-start feature using the meta-data in your application section:
<meta-data android:name="com.openback.AUTO_START" android:value="true" />

Parameters
autoStart boolean The auto-start mode.
Setting the auto-start with this method will override the meta-data.

isAutoStartEnabled

public static boolean isAutoStartEnabled()

Get the auto-start mode

setGDPRForgetUser

public static void setGDPRForgetUser(boolean gdprForgetUser)

When your user requests that all the data should be erased, set this value to true. It will inform the OpenBack server to remove all logs for the current user. All future logs will be erased after processing. If you wish to be fully GDPR compliant, you also need to enable GDPR in your application settings on the OpenBack Dashboard.

Parameters
gdprForgetUser boolean The GDPR forget user mode.

isGDPRForgetUserEnabled

public static boolean isGDPRForgetUserEnabled()

Get the GDPR forget user status

setCOPPACompliant

public static void setCOPPACompliant(boolean coppaCompliant)

If your application needs COPPA to be enabled, set the COPPA compliant status with this function. If COPPA is enabled, campaigns will not run unless compliant is set to true.

Parameters
coppaCompliant boolean The COPPA compliant mode.

isCOPPACompliant

public static boolean isCOPPACompliant()

Get the COPPA compliant status

setHIPAACompliant

public static void setHIPAACompliant(boolean hipaaCompliant)

If your application needs HIPAA to be enabled, set the HIPAA compliant status with this function. If HIPAA is enabled, campaigns will not run unless compliant is set to true.

Parameters
hipaaCompliant boolean The HIPAA compliant mode.

isHIPAACompliant

public static boolean isHIPAACompliant()

Get the HIPAA compliant status

Runtime

Constants

// The SDK Version
public final static String SDK_VERSION
// Minimum Android level support for this SDK
public final static int ANDROID_MIN_SDK_SUPPORT

start

public static boolean start()

Start OpenBack

stop

public static boolean stop()

Stop OpenBack

isStarted

public static boolean isStarted()

Get the running state of OpenBack

resetAll

public static void resetAll()

Reset all the current settings and user data. A new user will be created, and the library will behave as it would on fresh startup (using meta-dat, etc...).

checkNow

public static void checkNow()

Run the message checker

initialize

public static void initialize(@NonNull Context context);

Initialize OpenBack with the application context.

This method is called by com.openback.provider.OpenBackInitProvider when the application is launched. You do not need to call this method unless you disable the provider.

Parameters
context Context The application context.

Debug Logs

Constants

public @interface LogLevel {}
public final static int LOG_LEVEL_VERBOSE
public final static int LOG_LEVEL_DEBUG
public final static int LOG_LEVEL_INFO
public final static int LOG_LEVEL_WARN
public final static int LOG_LEVEL_ERROR
public final static int LOG_LEVEL_NONE

setDebugLogLevel

public static void setDebugLogLevel(@LogLevel int logLevel);

Set the public logging level.

Make sure you set the level to LOG_LEVEL_NONE in your release build to avoid leaking information.

Parameters
logLevel LogLevel The debug log level.

Custom Segments

Constants

public @interface CustomSegmentIndex {}
public final static int CUSTOM_SEGMENT_1
public final static int CUSTOM_SEGMENT_2
public final static int CUSTOM_SEGMENT_3
public final static int CUSTOM_SEGMENT_4
public final static int CUSTOM_SEGMENT_5
public final static int CUSTOM_SEGMENT_6
public final static int CUSTOM_SEGMENT_7
public final static int CUSTOM_SEGMENT_8
public final static int CUSTOM_SEGMENT_9
public final static int CUSTOM_SEGMENT_10

setCustomSegment

public static boolean setCustomSegment(@CustomSegmentIndex int segmentIndex, @Nullable String value)

Set a custom segment String value

Parameters
segmentIndex CustomSegmentIndex The custom segment index.
value String The custom segment string value.

setCustomSegment

public static boolean setCustomSegment(@CustomSegmentIndex int segmentIndex, long value)

Set a custom segment long value

Parameters
segmentIndex CustomSegmentIndex The custom segment index.
value long The custom segment long value.

setCustomSegment

public static boolean setCustomSegment(@CustomSegmentIndex int segmentIndex, double value)

Set a custom segment double value

Parameters
segmentIndex CustomSegmentIndex The custom segment index.
value double The custom segment double value.

setCustomSegment

public static boolean setCustomSegment(@CustomSegmentIndex int segmentIndex, @Nullable ArrayList<String> value)

Set a custom segment array of string value

Parameters
segmentIndex CustomSegmentIndex The custom segment index.
value ArrayList<String> The custom segment array of strings value.

getCustomSegment

@Nullable
public static Object getCustomSegment(@CustomSegmentIndex int segmentIndex)

Get a custom segment value

Parameters
segmentIndex CustomSegmentIndex The custom segment index.

getCustomSegmentAsString

public static String getCustomSegmentAsString(@CustomSegmentIndex int segmentIndex)

Get a custom segment String value

Parameters
segmentIndex CustomSegmentIndex The custom segment index.

getCustomSegmentAsLong

public static long getCustomSegmentAsLong(@CustomSegmentIndex int segmentIndex)

Get a custom segment long value

Parameters
segmentIndex CustomSegmentIndex The custom segment index.

getCustomSegmentAsDouble

public static double getCustomSegmentAsDouble(@CustomSegmentIndex int segmentIndex)

Get a custom segment double value

Parameters
segmentIndex CustomSegmentIndex The custom segment index.

removeAllCustomSegments

public static void removeAllCustomSegments()

Removes all the custom segments

Attributes

These are a set of pre-defined attributes but you are free to use your own.

public final static String USER_ADDRESS_LINE_1
public final static String USER_ADDRESS_LINE_2
public final static String USER_ADVERTISING_ID
public final static String USER_AGE
public final static String USER_CITY
public final static String USER_COUNTRY
public final static String USER_COUNTRY_CODE
public final static String USER_DATE_OF_BIRTH
public final static String USER_FIRST_NAME
public final static String USER_GENDER
public final static String USER_OPT_IN_UPDATES
public final static String USER_POST_CODE
public final static String USER_PROFESSION
public final static String USER_STATE
public final static String USER_SURNAME
public final static String USER_TITLE
public final static String USER_IDENTITY_1
public final static String USER_IDENTITY_2
public final static String USER_IDENTITY_3
public final static String USER_IDENTITY_4
public final static String USER_IDENTITY_5

setAttribute

public static void setAttribute(@NonNull String attributeKey, @Nullable Object attributeValue)

Set an attribute Object value

Parameters
attributeKey String The attribute key.
attributeValue Object The attribute object value.

setAttribute

public static void setAttribute(@NonNull String attributeKey, @NonNull String attributeValue)

Set an attribute String value

Parameters
attributeKey String The attribute key.
attributeValue String The attribute string value.

setAttribute

public static void setAttribute(@NonNull String attributeKey, long attributeValue)

Set an attribute long value

Parameters
attributeKey String The attribute key.
attributeValue long The attribute long value.

setAttribute

public static void setAttribute(@NonNull String attributeKey, double attributeValue)

Set an attribute double value

Parameters
attributeKey String The attribute key.
attributeValue double The attribute double value.

setAttribute

public static void setAttribute(@NonNull Map<String, Object> attributes)

Set multiple attributes.

Parameters
attributeKey String The attribute key.
attributeValue Map<String, Object> The attribute map values to add/merge.

getAttribute

@Nullable
public static Object getAttribute(@NonNull String attributeKey)

Get the attribute for the given key

Parameters
attributeKey String The attribute key.

getAttributeString

@Nullable
public static String getAttributeString(@NonNull String attributeKey)

Get the attribute as String for the given key

Parameters
attributeKey String The attribute key.

getAttributeLong

public static long getAttributeLong(@NonNull String attributeKey)

Get the attribute as long for the given key

Parameters
attributeKey String The attribute key.

getAttributeDouble

public static double getAttributeDouble(@NonNull String attributeKey)

Get the attribute as double for the given key

Parameters
attributeKey String The attribute key.

getAllAttributes

public static Map<String, Object> getAllAttributes()

Get all the attributes

removeAllAttributes

public static void removeAllAttributes()

Removes all the attribtues

Logging Goals

logGoal

public static boolean logGoal(@NonNull String goal, int step, double value)

Log a goal achieved

Parameters
goal String The achieved goal.
step int The goal step number.
value double The value associated with the goal step.

Trigger Event

triggerEvent

public static void triggerEvent(@NonNull String event, long delay)

Trigger an event.

Messages using the event trigger that match the event name will be triggered after the given delay (seconds).

Parameters
event String The event to trigger.
delay long The delay to wait before displaying the messages in seconds.

cancelEvent

public static void cancelEvent(@NonNull String event)

Cancel an event.

Parameters
event String The event to cancel.

Topics

getSubscribedTopics

public static List<String> getSubscribedTopics()

Get the list of subscribed topics

isSubscribedToTopic

public static boolean isSubscribedToTopic(@NonNull String topic)

Check if the given topic is part of the current subscribed topics

Parameters
topic String The topic code.

subscribeToTopic

public static boolean subscribeToTopic(@NonNull String topic)

Subscribe to a topic

Parameters
topic String The topic code.

subscribeToTopics

public static boolean subscribeToTopics(@NonNull List<String> topics)

Subscribe to multiple topics

Parameters
topics List<String> The list of topic codes.

unsubscribeFromTopic

public static boolean unsubscribeFromTopic(@NonNull String topic)

Unsubscribe from a topic

Parameters
topic String The topic code.

unsubscribeFromTopics

public static boolean unsubscribeFromTopics(@NonNull List<String> topics)

Unsubscribe from multiple topics

Parameters
topic List<String> The list of topic codes.

unsubscribeFromAllTopics

public static boolean unsubscribeFromAllTopics()

Unsubscribe from all topics

App Inbox

getAppInboxMessageCount

public static long getAppInboxMessageCount()

Get the total number of inbox messages

getAppInboxUnreadMessageCount

public static long getAppInboxUnreadMessageCount()

Get the number of unread inbox messages

getAppInboxMessages

@NonNull
public static List<AppInboxMessage> getAppInboxMessages()

Get all the inbox messages

getAppInboxReadMessages

@NonNull
public static List<AppInboxMessage> getAppInboxReadMessages()

Get all the read inbox messages

getAppInboxUnreadMessages

@NonNull
public static List<AppInboxMessage> getAppInboxUnreadMessages()

Get all the unread inbox messages

markAppInboxMessageAsRead

public static boolean markAppInboxMessageAsRead(@NonNull AppInboxMessage inboxMessage)

Mark a inbox message as read

Parameters
inboxMessage AppInboxMessage The app inbox message.

markAppInboxMessagesAsRead

public static boolean markAppInboxMessagesAsRead(@NonNull List<AppInboxMessage> inboxMessages)

Mark multiple inbox messages as read

Parameters
inboxMessages List<AppInboxMessage> The list of app inbox messages.

markAllAppInboxMessagesAsRead

public static boolean markAllAppInboxMessagesAsRead()

Mark all the inbox messages as read

removeAppInboxMessage

public static boolean removeAppInboxMessage(@NonNull AppInboxMessage inboxMessage)

Remove an inbox messages

Parameters
inboxMessage AppInboxMessage The app inbox message.

removeAppInboxMessages

public static boolean removeAppInboxMessages(@NonNull List<AppInboxMessage> messages)

Remove multiple inbox messages

Parameters
inboxMessages List<AppInboxMessage> The list app inbox messages.

removeAllAppInboxMessages

public static boolean removeAllAppInboxMessages()

Remove all the inbox messages

executeAppInboxMessage

public static boolean executeAppInboxMessage(@NonNull AppInboxMessage inboxMessage)

Execute the inbox message if actionable

Parameters
inboxMessage AppInboxMessage The app inbox message.

AppInboxMessage Class

public final class AppInboxMessage {
    public long inboxId;        // Internal inbox identifier
    public String title;        // Message title
    public String content;      // Message content
    public String payload;      // Message payload
    public String thumbnail;    // Message thumbnail path
    public long displayTime;    // Display time in epoch seconds
    public long expirationTime; // Expiration time in epoch seconds
    public boolean read;        // Message read state
    public boolean actionable;  // Message can be executed if true
}

Handling Inbox Change Events

You can register to broadcast intents sent by the App Inbox when a message is added to the inbox, read (from notification), or has expired.

// Intent action for event broadcast
public final static String APP_INBOX_ACTION
// Intent extra with event name
public final static String APP_INBOX_EVENT_EXTRA
// Intent extra with unread count
public final static String APP_INBOX_UNREAD_EXTRA
// A message was read event
public final static String APP_INBOX_MESSAGE_READ
// A message was added event
public final static String APP_INBOX_MESSAGE_ADDED
// A message expired event
public final static String APP_INBOX_MESSAGE_EXPIRED

The broadcast intent with action APP_INBOX_ACTION comes with 2 extra fields:

  • APP_INBOX_EVENT_EXTRA: (String) The event type (added, read, expired)
  • APP_INBOX_UNREAD_EXTRA: (long) The number of unread messages after the event occured

Example:

public class MyActivity extends AppCompatActivity {

    private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String event = intent.getStringExtra(OpenBack.APP_INBOX_EVENT_EXTRA);
            long unread = intent.getLongExtra(OpenBack.APP_INBOX_UNREAD_EXTRA, 0);
            switch (event) {
                case OpenBack.APP_INBOX_MESSAGE_ADDED:
                case OpenBack.APP_INBOX_MESSAGE_READ:
                case OpenBack.APP_INBOX_MESSAGE_EXPIRED:
                    // Handle inbox changes (e.g. refresh list, update badge...)
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LocalBroadcastManager.getInstance(getApplicationContext())
            .registerReceiver(mMessageReceiver, new IntentFilter(OpenBack.APP_INBOX_ACTION));
    }

    @Override
    protected void onDestroy() {
        LocalBroadcastManager.getInstance(getApplicationContext())
            .unregisterReceiver(mMessageReceiver);
        super.onDestroy();
    }
}

Firebase Messaging Handler

handleFcmMessage

public static boolean handleFcmMessage(@NonNull Map<String, String> data)

If your application already uses FCM message service class, call this method first to check if the message is intended for OpenBack.

Parameters
data Map<String, String> The data content of the Firebase message.

refreshToken

public static void refreshToken(@NonNull String token)

If your application already uses FCM message service class, call this method to update the device token.

Parameters
token String The new Firebase token.