Android SDK

Set up the TesterMob library

Add a small .aar file to your Android project so your dashboard can show when testers open your app and how long they stay. It takes about ten minutes.

Video walkthrough

Watch us add the library to a real Android Studio project and upload the build to Google Play Console.

Add the library

Download TesterMobLib.aar and copy it into your project’s app/libs/ folder. Then add it, along with Retrofit, to your app module’s build.gradle:

app/build.gradle
dependencies {
    implementation files('libs/TesterMobLib.aar')
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
}

Sync Gradle after saving the file.

Permissions

The library needs network access. Add these lines to AndroidManifest.xml, above the <application> tag:

AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Main activity

In your MainActivity, declare the tracker and your app ID above onCreate(). Copy the app ID from your TesterMob dashboard.

MainActivity.java
public static UserActivityTracker tracker;
public String appId = "app_id"; // copy your app ID from the dashboard

Then start the tracker inside onCreate():

MainActivity.java
tracker = new UserActivityTracker(this, appId);
tracker.sendUserActivity(appId);
tracker.getTesterMob();

Lifecycle methods

These methods tell TesterMob when a session starts and ends. Add them to MainActivity:

MainActivity.java
@Override
protected void onResume() {
    super.onResume();
    tracker.sendUserActivity(appId);
}

@Override
protected void onStart() {
    super.onStart();
    tracker.startTracking();
}

@Override
protected void onStop() {
    super.onStop();
    tracker.stopTracking();
}

Other activities

To track time spent on other screens, add start and stop calls to each of your other activities:

AnyOtherActivity.java
@Override
protected void onStart() {
    super.onStart();
    MainActivity.tracker.startTracking();
}

@Override
protected void onStop() {
    super.onStop();
    MainActivity.tracker.stopTracking();
}

Before you upload

  • The app ID in your code matches the one in your dashboard.
  • Both permissions are in AndroidManifest.xml.
  • You ran the build on a real device and saw a session appear in the dashboard.
  • The new build is uploaded to your closed testing track.

Stuck? Email support@testermob.com with your app ID and a screenshot of the error.