Android SDK

This page will guide you through the implementation of our Android SDK.

❗️

Caution!

This page documents a deprecated version, we highly recommend using the latest version documented here.

Account Set-Up and retrieving your API Key

Before we can get started with implementing the SDK, you should retrieve your API Key for your integration from the BitLabs Dashboard. If you haven't created an account yet, you can do so here and follow the instructions for the dashboard starting with Sign up & Set up.

App-level build.gradle file

Add the following code above the dependencies section of your app-level build.gradle file:

repositories {
   maven {
       url 'https://jitpack.io'
   }
}
repositories {
   maven {
       url 'https://jitpack.io'
   }
}

Adding Dependencies

dependencies {
   // other dependencies

   implementation 'com.github.BitBurst-GmbH:bitlabs-android-library:1.2.1'

   // other dependencies
}
dependencies {
   // other dependencies

   implementation 'com.github.BitBurst-GmbH:bitlabs-android-library:1.2.1'

   // other dependencies
}

Allowing your App to access the internet

If your app doesn't have this already, make sure to allow access to the internet.

//App Permissions
<uses-permission android:name="android.permission.INTERNET" />
//App Permissions
<uses-permission android:name="android.permission.INTERNET" />

Initiating the SDK

You will need to initiate the SDK before you can use it. You can do so with the following code.

BitLabsSDK.init(<context>, "YOUR-TOKEN", "YOUR-USER-ID");
BitLabsSDK.Companion.init(<context>, "YOUR-TOKEN", "YOUR-USER-ID");

This is where you will need the API key from the dashboard, as you will need to replace "YOUR-TOKEN" with it. For "YOUR-USER-ID", you will need to dynamically insert the user id for each app user. Make sure the id used here is unique and that it does not change, as the user's profile will be stored under this id.

Using the SDK

Show BitLabs to the user

Now it's time to use the BitLabs SDK so that your users can start taking surveys. Call the .show() function to open the Offer Wall/Direct Link. BitLabs will show up and the user will see qualifications or surveys.

BitLabsSDK.show(<context>)
BitLabsSDK.Companion.show(<context>);

Theoretically, this is all you have to do. Anything below is optional but can improve the user experience.

.hasSurveys() - Check if there's something to do for the user

You can use .hasSurveys() to check if a survey is available for the user. This function will return true whenever there's a survey or a qualification question available for the user. If there's, it will return true.

BitLabsSDK.hasSurveys(
    // NOTE: the offerwall can be shown without checking for surveys first
   object: Listener<Boolean> {
       override fun onResponse(response: Boolean) {
           BitLabsSDK.show(this)
       }
   },
   object: ErrorListener {
       override fun onError(error: Error) {
           Log.e("BitLabs", error.toString())
       }
   }
)
BitLabsSDK.Companion.hasSurveys(
       // NOTE: the offerwall can be shown without checking for surveys first
       response -> BitLabsSDK.Companion.show(this),
       error -> Log.e("BitLabs", error.toString())
)

.onReward() - Client Side Callbacks

You can use .onReward() to check to receive callbacks to reward the user. We highly recommend using server-to-server callbacks instead! Please do not use this in apps where the user can withdraw real currency, as it might be exploitable.
However, if your app stores user data locally and does not sync with a server, this would be an option to still use BitLabs to reward your users.

BitLabsSDK.onReward(
   object: RewardListener<Float> {
       override fun onReward(payout: Float) {
           Log.i("BitLabs", "Payout of: ${payout}"))
       }
   }
)
BitLabsSDK.Companion.onReward(
   payout->Log.i("BitLabs", "Payout of: " + payout)
);

.setTags() - Add Tags to receive in your callbacks

You can use .setTags() to pass additional parameters to the SDK you would like to receive in your callback.

val tags: MutableMap<String, Any> = java.util.HashMap()
tags["my_tag"] = "new_user"
tags["is_premium"] = true
BitLabsSDK.setTags(tags)
Map<String, Object> tags = new HashMap<>();
tags.put("my_tag", "new_user");
tags.put("is_premium", true);
BitLabsSDK.Companion.setTags(tags);

Your next Step

You have now implemented BitLabs with your project. If you haven't done it already, it is time to configure server-to-server callbacks and the look and feel of your app.

Did this page help you?