java.lang.Object | ||
↳ | ButtonPrivate | |
↳ | com.usebutton.sdk.Button |
Main entry point to the Button SDK. There's two steps involved in initializing the Button SDK:
android.app.Application.onCreate()
<meta-data android:name="com.usebutton.applicationid" android:value="app-0000000000000000"/>
public class SampleApplication extends android.app.Application { public void onCreate() { super.onCreate(); if (BuildConfig.DEBUG) { Button.getButton(this).enableDebugLogging(); } Button.getButton(this).start(); } }
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Button.ActionListener | Callback interface for getAction(String, ButtonContext, ActionListener) which
will call onAction(AppAction) if an action is available given the
provided Button ID and ButtonContext. |
||||||||||
Button.DeepLinkListener | Callback interface for checkForDeepLink(Context, DeepLinkListener) which
will invoke onDeepLink(Intent) with a VIEW intent for a deferred deep link if such
is found. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This method will check if there's any pending deferred deep link for this user
after an installation.
| |||||||||||
Disable SDK debug logging, see
enableDebugLogging() for more details. | |||||||||||
Will enable useful debug logging from the Button SDK (tag Button).
| |||||||||||
If you need to customize the Button experience past styling the ButtonDropin you can use this
method to get full control.
| |||||||||||
Gets the shared Button instance & lazily instantiates if not yet created.
| |||||||||||
You can use this method to check if the current user came in through a Button deep link or not (null)
| |||||||||||
Clears any session information and effectively creates a new customer.
| |||||||||||
Call this if you need to have the Button SDK reload its language settings from
Locale.getDefault() (in case you're forcing a different language in your app
from the device default. | |||||||||||
Report a custom named event with an optional dictionary of parameters (JSONObject),
for example a registration or a restaurant table reservation.
| |||||||||||
This method is deprecated.
Please use our order API - https://www.usebutton.com/developers/api-reference/#create-order.
Will report an order attribution and its value & currency to this user, the order total will be a sum of all the line items. LineItem eggs = new LineItem("sku-123", 1099); LineItem milk = new LineItem("sku-567", 399, 3); LineItem onions = new LineItem("sku-89", 199, 1, "White Onion"); List omeletteItems = Arrays.asList(eggs, milk, onions); Button.getButton(context).reportOrder(omeletteItems, "USD", UUID.randomUUID().toString()); | |||||||||||
This method is deprecated.
Please use our order API - https://www.usebutton.com/developers/api-reference/#create-order.
Will report an order attribution and its value & currency to this user. | |||||||||||
This method is deprecated.
Use
setUserIdentifier(String) instead. Will be removed in next major version.
| |||||||||||
Call with a non-
null value to associate your own unique identifier with the current Button
session. | |||||||||||
Initializes Button for your application, preferably called from
android.app.Application.onCreate() . | |||||||||||
Ceases all Button activity.
| |||||||||||
Convenience method to check if a promotion will be filled given a placement ID and context.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
This method will check if there's any pending deferred deep link for this user
after an installation. You'd want to check this in your main launcher intent activity's onCreate.
For most application you'd only need to override onDeepLink(Intent)
and call
startActivity(Intent)
.
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); com.usebutton.sdk.Button.checkForDeepLink(new com.usebutton.sdk.Button.DeepLinkListener() { @Override public void onDeepLink(final Intent intent) { // Deep link received, let's open it. startActivity(intent); } @Override public void onNoDeepLink() {} }); setContentView(R.layout.your_activity); // ... }
Disable SDK debug logging, see enableDebugLogging()
for more details.
Will enable useful debug logging from the Button SDK (tag Button).
We recommend you call this function before start()
.
Use adb logcat ButtonSDK:D *:S
to filter on Button log statements only.
If you need to customize the Button experience past styling the ButtonDropin you can use this
method to get full control.
Most integrators should use a ButtonDropin
in their layout instead.
Code example:
final Location venue = new Location("Madison Square Garden"); venue.putIdentifier(Identifiers.IDENTIFIER_TICKETMASTER, "483329"); final ButtonContext context = ButtonContext.withSubjectLocation(venue); Button.getButton(this).getAction("btn-your-id", context, new Button.ActionListener() { @Override public void onAction(final AppAction action) { // Let's setup our Button android.widget.Button button = findViewById(R.id.activity_buy_tickets_button); final Preview preview = action.getPreview(); final Text previewText = preview.getText(); // This will set both text and text color. previewText.applyTo(button); // Let's also style our Button with some brand colors button.setBackgroundColor(preview.getBackgroundColor()); // Important that you register a click listener to invoke the action button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { action.invokePreview(v.getContext()); } }); } @Override public void onNoAction() { android.widget.Button button = findViewById(R.id.activity_buy_tickets_button); button.setVisibility(View.GONE); } }); @Override public void onNoAction() { android.widget.Button button = findViewById(R.id.activity_buy_tickets_button); button.setVisibility(View.GONE); } });
buttonId | you find your Button ID in the Dashboard. |
---|---|
buttonContext | the context describing information relevant to the user for this screen
or app state, see ButtonContext for more information. |
actionListener | callback for result, see Button.ActionListener for more information.
|
Gets the shared Button instance & lazily instantiates if not yet created.
You can use this method to check if the current user came in through a Button deep link or not (null)
Clears any session information and effectively creates a new customer.
Use when e.g. the user logs out or changes in the host application.
Don't forget to also set the user identifier upon registration or login by calling
setUserIdentifier(String)
.
Call this if you need to have the Button SDK reload its language settings from
Locale.getDefault()
(in case you're forcing a different language in your app
from the device default.
Button.getButton(context).start(); // started with device default Locale.setDefault(Locale.forLanguageTag("nb-NO")); Button.getButton(context).onLocaleChanged(); // SDK will now reload its internal dictionary
Report a custom named event with an optional dictionary of parameters (JSONObject), for example a registration or a restaurant table reservation.
name | (required), e.g. "registration", "cancellation", "booking", "reservation" |
---|---|
parameters | (optional) |
This method is deprecated.
Please use our order API - https://www.usebutton.com/developers/api-reference/#create-order.
Will report an order attribution and its value & currency to this user,
the order total will be a sum of all the line items.
LineItem eggs = new LineItem("sku-123", 1099); LineItem milk = new LineItem("sku-567", 399, 3); LineItem onions = new LineItem("sku-89", 199, 1, "White Onion"); List omeletteItems = Arrays.asList(eggs, milk, onions); Button.getButton(context).reportOrder(omeletteItems, "USD", UUID.randomUUID().toString());
Parameters
lines an optional list of order lines, see LineItem
for details.currencyCode the currency of this order e.g. USD or NOK. See ISO-4217 for a complete list of supported currency codes or use getCurrencyCode()
.orderId your order ID
This method is deprecated.
Please use our order API - https://www.usebutton.com/developers/api-reference/#create-order.
Will report an order attribution and its value & currency to this user.
amountTotal | closest value in the smallest decimal unit for this currency. For USD $1 would be 100. |
---|---|
currencyCode | the currency of this order e.g. USD or NOK.
See ISO-4217
for a complete list of supported currency codes or use getCurrencyCode() . |
orderId | your order ID |
This method is deprecated.
Use setUserIdentifier(String)
instead. Will be removed in next major version.
Call with a non-null
value to associate your own unique identifier with the current Button
session. For example, this value can be a username, e-mail address, or profile ID. It can be used
with certain Button backend reporting features.
You should call this when you've established a user's identify, like after a sign up or login.
Don't forget to mirror this with calling logout()
when the user logs out.
userIdentifier | the unique id to associate with this session |
---|
Initializes Button for your application, preferably called from android.app.Application.onCreate()
.
Remember to add your application ID to your AndroidManifest.xml first, see Button
for example
Ceases all Button activity.
Convenience method to check if a promotion will be filled given a placement ID and context. See ButtonDropin
for more information about context. You can use this to e.g. show/hide ButtonDropin
's layout container.
For instructions on finding your buttonId, see Button
<com.usebutton.sdk.ButtonDropin
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="10dp"
button:buttonId="your-button-id"
button:textColor="@color/white"
button:textSize="18dp"
/>
buttonId | same buttonId as you would use in your layout declaration for ButtonDropin |
---|---|
context | See ButtonDropin |
listener | will be called with onPrepared(true) if we will fill a button for this context
|