public interface IAppboy
Appboy.configure(Context, AppboyConfig)
with your Braze API key.Appboy.getInstance(android.content.Context)
.openSession(android.app.Activity)
and closeSession(android.app.Activity)
in your Activity's onStart() and onStop() respectively.
Appboy.getInstance(android.content.Context)
multiple times
and with different Activities. Braze uses the initial Activity that is passed in and grabs the Application context,
which it then uses for the length of the process.
// Creating an IAppboy instance
IAppboy appboy = Appboy.getInstance(this);
// The Braze API key is read from the appboy.xml file. Be sure to include the 'com_appboy_api_key' string resource.
<resources>
<string translatable="false" name="com_appboy_api_key">YOUR-API-KEY</string>
...
openSession(Activity)
and closeSession(Activity)
in every Activity and can additionally register for in-app messages.
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
registerActivityLifecycleCallbacks(new AppboyLifecycleCallbackListener());
}
}
openSession(Activity)
and closeSession(Activity)
in every Activity. Check your
AndroidManifest.xml file for the list of Activities defined in your app and be sure to add these two method calls
in the manner shown below. Forgetting to add them may result in incorrect session count.
@Override
public void onStart() {
super.onStart();
// Opens a new Braze session.
Appboy.getInstance(this).openSession(this);
}
@Override
public void onStop() {
// Closes the Braze session.
Appboy.getInstance(this).closeSession(this);
super.onStop();
}
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
...
// Sets the api key in code, overriding the xml defined key
AppboyConfig appboyConfig = new AppboyConfig.Builder()
.setApiKey("your-api-key")
.build();
Appboy.configure(this, appboyConfig);
}
}
However, this is not suggested if you have long running code to determine the API key. Disk reads and writes,
slow or blocking code, and network requests are examples of things that should be avoided.
Modifier and Type | Method and Description |
---|---|
void |
changeUser(java.lang.String userId)
When you first start using Braze on a device, the user is considered "anonymous".
|
void |
closeSession(android.app.Activity activity)
Closes the current session.
|
Card |
deserializeContentCard(org.json.JSONObject contentCardJson)
Constructs a Content Card from its
Card.forJsonPut() output. |
Card |
deserializeContentCard(java.lang.String contentCardString)
Helper method for
deserializeContentCard(JSONObject) . |
IInAppMessage |
deserializeInAppMessageString(java.lang.String inAppMessageString)
This function returns a deserialized in-app message from the message JSON string.
|
IAppboyImageLoader |
getAppboyImageLoader()
Returns the
IAppboyImageLoader for the Braze instance. |
java.lang.String |
getAppboyPushMessageRegistrationId()
Returns the FCM/ADM/Baidu registration Id used to send the device push messages.
|
java.util.List<Card> |
getCachedContentCards()
Retrieves the offline/cached list of Content Cards from offline storage.
|
int |
getContentCardCount()
Retrieves information about Content Cards based on the currently cached data.
|
long |
getContentCardsLastUpdatedInSecondsFromEpoch()
Retrieves information about Content Cards based on the currently cached data.
|
int |
getContentCardUnviewedCount()
Retrieves information about Content Cards based on the currently cached data.
|
AppboyUser |
getCurrentUser()
Returns the user currently being tracked by Braze.
|
void |
getCurrentUser(IValueCallback<AppboyUser> completionCallback)
Returns the user currently being tracked by Braze.
|
java.lang.String |
getInstallTrackingId()
Returns a unique device ID for install tracking.
|
void |
logContentCardsDisplayed()
Reports that Content Cards were displayed.
|
void |
logCustomEvent(java.lang.String eventName)
Reports a custom named event.
|
void |
logCustomEvent(java.lang.String eventName,
AppboyProperties properties)
Reports a custom named event.
|
void |
logFeedCardClick(java.lang.String cardId)
Deprecated.
Please call
Card.logClick() instead to log a click.
Reports a feed card was clicked. |
void |
logFeedCardImpression(java.lang.String cardId)
Deprecated.
Please call
Card.logImpression() instead to log an impression.
Reports a feed card was displayed to the user. Card impressions tracks how many times a card has been seen. Impressions should only be reported once the card becomes viewable to the user. Cards that are part of the stream but not visible should not log a card impression. If a card is viewed more than once in a particular view, it generates only one impression. If closed and reopened, a card will again generate an impression. |
void |
logFeedDisplayed()
Reports that the feed was displayed.
|
void |
logPurchase(java.lang.String productId,
java.lang.String currencyCode,
java.math.BigDecimal price)
In order to log a purchase, switch to
logPurchase(String productId, String currencyCode, BigDecimal price, int quantity).
|
void |
logPurchase(java.lang.String productId,
java.lang.String currencyCode,
java.math.BigDecimal price,
AppboyProperties properties)
In order to log a purchase, switch to
logPurchase(String productId, String currencyCode, BigDecimal price, int quantity, AppboyProperties properties).
|
void |
logPurchase(java.lang.String productId,
java.lang.String currencyCode,
java.math.BigDecimal price,
int quantity)
In order to log a purchase, switch to
logPurchase(String productId, String currencyCode, BigDecimal price, int quantity, AppboyProperties properties).
|
void |
logPurchase(java.lang.String productId,
java.lang.String currencyCode,
java.math.BigDecimal price,
int quantity,
AppboyProperties properties)
Reports that the current user made an in app purchase.
|
void |
logPushNotificationActionClicked(java.lang.String campaignId,
java.lang.String actionId,
java.lang.String actionType)
Reports that the user clicked on a push notification action button.
|
void |
logPushNotificationOpened(android.content.Intent intent)
Reports that the user clicked on the push notification.
|
void |
logPushNotificationOpened(java.lang.String campaignId)
When possible, logPushNotificationOpened(Intent intent) should be used instead.
|
void |
logPushStoryPageClicked(java.lang.String campaignId,
java.lang.String pageId)
Reports that the user clicked on a push story page.
|
void |
openSession(android.app.Activity activity)
Opens a new session or resumes the previous session.
|
void |
registerAppboyPushMessages(java.lang.String registrationId)
Registers the device as eligible to receive push notifications from Braze.
|
<T> void |
removeSingleSubscription(IEventSubscriber<T> subscriber,
java.lang.Class<T> eventClass)
Removes a single subscription associated with the given activity and event class.
|
void |
requestContentCardsRefresh(boolean fromCache)
Requests an immediate refresh of Content Cards.
|
void |
requestFeedRefresh()
Requests an immediate refresh of the news feed from the Braze server.
|
void |
requestFeedRefreshFromCache()
Requests a refresh of the news feed from offline storage.
|
void |
requestGeofences(double latitude,
double longitude)
Requests a refresh of Braze Geofences for the specified GPS coordinate.
|
void |
requestImmediateDataFlush()
Requests an immediate flush of any analytics data waiting to be sent to Appboy's servers.
|
void |
setAppboyImageLoader(IAppboyImageLoader appboyImageLoader)
Sets the
IAppboyImageLoader for the Braze instance. |
void |
setGoogleAdvertisingId(java.lang.String googleAdvertisingId,
boolean isLimitAdTrackingEnabled)
Sets the Google Advertising ID and associated ad-tracking enabled field for this device.
|
void |
subscribeToContentCardsUpdates(IEventSubscriber<ContentCardsUpdatedEvent> subscriber)
Subscribes to Content Cards events.
|
void |
subscribeToFeedUpdates(IEventSubscriber<FeedUpdatedEvent> subscriber)
Subscribes to news feed events.
|
void |
subscribeToNetworkFailures(IEventSubscriber<BrazeNetworkFailureEvent> subscriber)
Subscribes to network failures that have occurred within the SDK.
|
void |
subscribeToNewInAppMessages(IEventSubscriber<InAppMessageEvent> subscriber)
Subscribes to in-app message events.
|
void |
subscribeToSessionUpdates(IEventSubscriber<SessionStateChangedEvent> subscriber)
Subscribes to Session start and close events.
|
void openSession(android.app.Activity activity)
openSession(Activity)
within the session timeout
of a call to closeSession(Activity)
will cause the previous session to be resumed. This
is done so that transitions from one Activity to another do not create a new session each time. This must be
called in every Activity's onStart method if using a manual session handling integration.activity
- The current Activity.void closeSession(android.app.Activity activity)
openSession(Activity)
within the session timeout. This must be called every the Activity's onStop method if using a manual session handling integration.activity
- The current Activity.void logCustomEvent(java.lang.String eventName)
eventName
- The String identifier for the event to track. Best practice is to track generic
events useful for segmenting, instead of specific user actions (i.e. track
watched_sports_video instead of watched_video_adrian_peterson_td_mnf).void logCustomEvent(java.lang.String eventName, AppboyProperties properties)
eventName
- The String identifier for the event to track. Best practice is to track generic
events useful for segmenting, instead of specific user actions (i.e. track
watched_sports_video instead of watched_video_adrian_peterson_td_mnf).properties
- An object containing key-value properties describing this event. Property names
are non-empty strings <= 255 characters, with no leading dollar signs.
Property values can be integers, floats, booleans, java.util.Date objects,
or strings <= 255 characters.void logPurchase(java.lang.String productId, java.lang.String currencyCode, java.math.BigDecimal price)
void logPurchase(java.lang.String productId, java.lang.String currencyCode, java.math.BigDecimal price, AppboyProperties properties)
void logPurchase(java.lang.String productId, java.lang.String currencyCode, java.math.BigDecimal price, int quantity)
void logPurchase(java.lang.String productId, java.lang.String currencyCode, java.math.BigDecimal price, int quantity, AppboyProperties properties)
productId
- The String identifier for the product purchased. Usually the Google Play SKU.currencyCode
- Currencies should be represented as an ISO 4217 currency code. Supported
currency symbols include: AED, AFN, ALL, AMD, ANG, AOA, ARS, AUD, AWG, AZN,
BAM, BBD, BDT, BGN, BHD, BIF, BMD, BND, BOB, BRL, BSD, BTC, BTN, BWP, BYR,
BZD, CAD, CDF, CHF, CLF, CLP, CNY, COP, CRC, CUC, CUP, CVE, CZK, DJF, DKK,
DOP, DZD, EEK, EGP, ERN, ETB, EUR, FJD, FKP, GBP, GEL, GGP, GHS, GIP, GMD,
GNF, GTQ, GYD, HKD, HNL, HRK, HTG, HUF, IDR, ILS, IMP, INR, IQD, IRR, ISK,
JEP, JMD, JOD, JPY, KES, KGS, KHR, KMF, KPW, KRW, KWD, KYD, KZT, LAK, LBP,
LKR, LRD, LSL, LTL, LVL, LYD, MAD, MDL, MGA, MKD, MMK, MNT, MOP, MRO, MTL,
MUR, MVR, MWK, MXN, MYR, MZN, NAD, NGN, NIO, NOK, NPR, NZD, OMR, PAB, PEN,
PGK, PHP, PKR, PLN, PYG, QAR, RON, RSD, RUB, RWF, SAR, SBD, SCR, SDG, SEK,
SGD, SHP, SLL, SOS, SRD, STD, SVC, SYP, SZL, THB, TJS, TMT, TND, TOP, TRY,
TTD, TWD, TZS, UAH, UGX, USD, UYU, UZS, VEF, VND, VUV, WST, XAF, XAG, XAU,
XCD, XDR, XOF, XPD, XPF, XPT, YER, ZAR, ZMK, ZMW and ZWL.
Any other provided currency symbol will result in a logged warning and no other
action taken by the SDK.price
- The price paid. Base units depend on the currency. As an example, USD should be
reported as Dollars.Cents, whereas JPY should be reported as a whole number of Yen.
All provided BigDecimal values will have RoundingMode.HALF_UP rounding applied
such that a maximum of two digits exist after the decimal point. May be negative.quantity
- The quantity of items purchased expressed as a whole number. Must be greater
than zero.properties
- A map of key-value properties describing this purchase. Property names
are non-empty strings <= 255 characters, with no leading dollar signs.
Property values can be integers, floats, booleans, datetimes
(of the formats "%FT%T%z", "%Y-%m-%d %H:%M:%S", "%Y-%m-%d", "%m/%d/%Y"),
or strings <= 255 characters.
Note: The productId and currencyCode are trimmed of any whitespace characters before being
sent to Braze.
void logPushNotificationOpened(java.lang.String campaignId)
campaignId
- The ID of the campaign that triggered the push notification. This can be found as
an extra in the push notification intent.void logPushNotificationOpened(android.content.Intent intent)
intent
- The push notification intent.void logPushNotificationActionClicked(java.lang.String campaignId, java.lang.String actionId, java.lang.String actionType)
campaignId
- The ID of the campaign that triggered the push notification. This can be found as
an extra in the push notification intent.actionId
- The ID of the action button that was clicked.actionType
- The action type from the intent's string extra under Constants.APPBOY_ACTION_TYPE_KEY
.void logPushStoryPageClicked(java.lang.String campaignId, java.lang.String pageId)
campaignId
- The ID of the campaign that triggered the push notification. This can be found as
an extra in the push notification intent.pageId
- The ID of the push story page that was clicked.void logContentCardsDisplayed()
void logFeedDisplayed()
void requestContentCardsRefresh(boolean fromCache)
subscribeToContentCardsUpdates(IEventSubscriber)
fromCache
- whether to request data from offline storage.void requestFeedRefresh()
void requestFeedRefreshFromCache()
requestFeedRefresh()
.void requestImmediateDataFlush()
void subscribeToContentCardsUpdates(IEventSubscriber<ContentCardsUpdatedEvent> subscriber)
ContentCardsUpdatedEvent
.
removeSingleSubscription(com.appboy.events.IEventSubscriber, Class)
.
subscriber
- A callback that will be executed when Content Cards are updated.void subscribeToFeedUpdates(IEventSubscriber<FeedUpdatedEvent> subscriber)
FeedUpdatedEvent
.
removeSingleSubscription(com.appboy.events.IEventSubscriber, Class)
.
subscriber
- A callback that should be executed when the news feed is updated.void subscribeToNewInAppMessages(IEventSubscriber<InAppMessageEvent> subscriber)
InAppMessageEvent
.
removeSingleSubscription(com.appboy.events.IEventSubscriber, Class)
.
subscriber
- A callback that should be executed when the news feed is updated.void subscribeToSessionUpdates(IEventSubscriber<SessionStateChangedEvent> subscriber)
SessionStateChangedEvent
.
removeSingleSubscription(com.appboy.events.IEventSubscriber, Class)
.
subscriber
- A callback that will be executed when a session is created or sealed.void subscribeToNetworkFailures(IEventSubscriber<BrazeNetworkFailureEvent> subscriber)
subscriber
- A callback that will be executed when a network failure event has occurred.<T> void removeSingleSubscription(IEventSubscriber<T> subscriber, java.lang.Class<T> eventClass)
subscriber
- The callback which is currently subscribed.eventClass
- The Event class which this IEventSubscriber is subscribed to.void changeUser(java.lang.String userId)
AppboyUser
can be retrieved at any time using getCurrentUser()
.userId
- An external user identifier. May not be longer than Constants.USER_ID_MAX_LENGTH_BYTES
.getCurrentUser()
AppboyUser getCurrentUser()
AppboyUser
is available. Please use
getCurrentUser(IValueCallback)
for the asynchronous version of this method.void getCurrentUser(IValueCallback<AppboyUser> completionCallback)
getCurrentUser()
for the synchronous version of this method.completionCallback
- that has IValueCallback.onSuccess(T)
called with a non-null AppboyUser
or IValueCallback.onError()
called otherwise.void registerAppboyPushMessages(java.lang.String registrationId)
registrationId
- The registration ID, or for apps integrating Baidu Cloud Push, the Baidu user idjava.lang.String getAppboyPushMessageRegistrationId()
java.lang.String getInstallTrackingId()
IAppboyImageLoader getAppboyImageLoader()
IAppboyImageLoader
for the Braze instance.void setAppboyImageLoader(IAppboyImageLoader appboyImageLoader)
IAppboyImageLoader
for the Braze instance. This IAppboyImageLoader
is used for all image relatedappboyImageLoader
- The image loader to be set for the Braze instance. If null, then the existing image loader is unchanged.int getContentCardCount()
requestContentCardsRefresh(boolean)
int getContentCardUnviewedCount()
requestContentCardsRefresh(boolean)
long getContentCardsLastUpdatedInSecondsFromEpoch()
requestContentCardsRefresh(boolean)
java.util.List<Card> getCachedContentCards()
void setGoogleAdvertisingId(java.lang.String googleAdvertisingId, boolean isLimitAdTrackingEnabled)
googleAdvertisingId
- The Google Advertising ID.isLimitAdTrackingEnabled
- Whether ad-tracking is enabled for the Google Advertising ID.IInAppMessage deserializeInAppMessageString(java.lang.String inAppMessageString)
inAppMessageString
- The in-app message JSON stringCard deserializeContentCard(java.lang.String contentCardString)
deserializeContentCard(JSONObject)
.contentCardString
- The string content of a Content Card's
JSONObject
obtained via JSONObject.toString()
.Card deserializeContentCard(org.json.JSONObject contentCardJson)
Card.forJsonPut()
output. Useful for caching Content Card
data and recreating them for your own purposes.
Card
. I.e. clicks and
impressions can be logged on the returned object.contentCardJson
- The JSONObject
representation of a Content Card
as obtained via Card.forJsonPut()
.void requestGeofences(double latitude, double longitude)
latitude
- A valid GPS latitude in range (-90, 90)longitude
- A valid GPS longitude in range (-180, 180)AppboyConfig.Builder#setAutomaticGeofenceRequestsEnabled(boolean)
,
ValidationUtils.isValidLocation(double, double)
@Deprecated void logFeedCardImpression(java.lang.String cardId)
Card.logImpression()
instead to log an impression.
cardId
- The ID of the feed card.Card.logImpression()
@Deprecated void logFeedCardClick(java.lang.String cardId)
Card.logClick()
instead to log a click.
cardId
- The ID of the feed card.Card.logClick()