Get Started on
Android

Get Started

Welcome to the Button Android Getting Started guide. This guide will walk you through adding the SDK to your app and will prepare you to use any of the Button Publisher products. We will:

  • Include the Button SDK in your app
  • Start the Button SDK
  • Configure User Attribution

From here you can begin using Button Purchase Path or Button Actions.


Add the Button SDK

JFrog Bintray

The easiest way to include the Button SDK is by using Gradle. To do this, simply add the Button SDK to your app's build.gradle file in the dependencies.

compile 'com.usebutton:android-sdk:5+'

Note: We strictly follow semantic versioning, but sometimes compatibility issues can still arise. It’s best practice to use the latest version and update your build.gradle each time a new SDK version is available.

Allow JFrog Bintray access to your project's build.gradle file and add the Google Maven repository.

allprojects {
    repositories {
        jcenter()
        maven {
          url "https://maven.google.com"
        }
    }
}

Add Button to your app's build.gradle file so it looks as below.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.0.1'
    testCompile 'junit:junit:4.12'

    // Button SDK
    compile 'com.usebutton:android-sdk:5+'
}

Start the SDK

To initialize a Button in your app, your app ID is needed, which can be found in the Button Dashboard. If you're a loyalty Publisher, you must attribute your users' IDs through Button. You must initialize your Button in your AndroidManifest.xml within the application tag.

In the AndroidManifest.xml file, add Button within the application tag to initialize your Button.

<application>

    <activity>
      <!-- your activities  -->
    </activity>

    <!--Button SDK-->
    <meta-data
        android:name="com.usebutton.applicationid"
        android:value="YOUR_BUTTON_APP_ID"
        />
</application>

Import the SDK at the top of the file and start it. This should be called when your application class is created.

import com.usebutton.sdk.Button

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        Button.getButton(this).start()
    }
}
import com.usebutton.sdk.Button;

public class MyApplication extends Application {
  @Override
  public void onCreate() {
      super.onCreate();
      Button.getButton(this).start();
  }
}

Configure user attribution

You can associate all Button activity with one of your users by setting their User Identifier. This can either be your user ID, email or a stable hash of one. You can use this later to look up orders, activity and identify the user in Webhooks.

Button.getButton(this).setUserIdentifier("someuser@usebutton.com")
Button.getButton(this).setUserIdentifier("someuser@usebutton.com");

If your app offers logout functionality, you should make sure to invoke the SDK's logout feature during your logout handler.

Button.getButton(this).logout()
Button.getButton(this).logout();

Note: You will also need to set the user identifier upon completion of a user log in or sign up.

For more information on user attribution, see this guide.


Proguard rules

If your app is using Proguard (minifyEnabled true in your build.gradle) make sure that the proguard rules below are in effect in your rules file. This file is usually located in yourapp/proguard-rules.pro, or its location is specified in build.gradle, look for proguardFiles in your default or variant configuration (note: this can be multiple files).

-keepattributes Exceptions,InnerClasses,EnclosingMethod
-keep class com.usebutton.** { *; }
-keepclassmembers class * implements android.os.Parcelable {
    static ** CREATOR;
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient { public *; }

Run your app

You should see printed to the console:

Configured successfully App ID: <YOUR_BUTTON_APP_ID>

If you don't, try using debug mode to figure out why.


Start using Button

You're now ready to start using Button. What would you like to do?