# Android Integration

{% hint style="warning" %}
**Before you start**&#x20;

To set up the PubScale Offerwall, you’ll need to add your app to our platform. Follow this guide for instructions on [how to set up your app](https://pubscale.gitbook.io/offerwall-sdk/1.0.10/basic-integration/setting-up-your-app). Once completed, you will receive a unique 8-digit app ID.
{% endhint %}

{% hint style="info" %}
You can download the Sample integration from [GitHub](https://github.com/greedygame/demo-offerwall-android)
{% endhint %}

{% embed url="<https://www.youtube.com/watch?v=Qngthh24lsE>" %}
Offerwall Android SDK integration video tutorial
{% endembed %}

## 1. Add this to your build.gradle file

Add the below line inside the **dependencies** block in your build.gradle file. Once added, clean build and rebuild the project.

{% tabs %}
{% tab title="Kotlin Script" %}

```kts
implementation("com.pubscale.sdkone:offerwall:1.0.10")
```

{% endtab %}

{% tab title="Groovy" %}

```groovy
implementation 'com.pubscale.sdkone:offerwall:1.0.10'
```

{% endtab %}
{% endtabs %}

## 2. Configure proguard rules

For the SDK to work properly in release(obfuscated/minified) builds, add the following rules in your proguard-rules.pro file.

{% code title="proguard-rules.pro" %}

```properties

-keep class com.pubscale.sdkone.offerwall.** {*;}
-keep class com.pubscale.caterpillar.analytics.** {*;}
#Supporting R8 full mode
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response
```

{% endcode %}

## 3. Initializing the OfferWall

You must initialize the SDK before using the SDK. To do this, call `Offerwall.init(OfferWallConfig, OfferWallInitListener)` .

### **3.1. Parameters for init call:**

* **OfferWallConfig offerWallConfig:** An object to pass configuration-related info to the SDK while initializing. Refer below for how to create an object of OfferWallConfig.
* **OfferWallInitListener offerWallInitListener:** A listener that informs you if the SDK initialization was successful or not. In case of failure, it will also give you a string stating the cause of the failure. This parameter is optional.&#x20;

### **3.2. Creating OfferWallConfig object:**

Create an instance of OfferWallConfig using the builder class OfferWallConfig.Builder by passing the context and your PubScale app ID.

{% hint style="info" %}
Obtain your **PubScale app ID** from the [PubScale Dashboard](https://dashboard.pubscale.com) by [adding your app and configuring the offerwall.](https://pubscale.gitbook.io/offerwall-sdk/1.0.10/basic-integration/setting-up-your-app) Once completed, you will receive a unique 8-digit app ID.
{% endhint %}

{% hint style="info" %}
Use sandbox environment app ID for testing purposes.&#x20;

[sandbox-environment](https://pubscale.gitbook.io/offerwall-sdk/1.0.10/sandbox-environment/sandbox-environment "mention") - Learn how to setup Sandbox environment
{% endhint %}

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import com.pubscale.sdkone.offerwall.OfferWallConfig
..
..
val offerWallConfig = OfferWallConfig.Builder(context, "YOUR_PUBSCALE_APP_ID")
   .setUniqueId("unique_id")
   .build()
```

{% endtab %}

{% tab title="Java" %}

```java
import com.pubscale.sdkone.offerwall.OfferWallConfig
..
..
OfferWallConfig offerWallConfig =
       new OfferWallConfig.Builder(context, "YOUR_PUBSCALE_APP_ID")
               .setUniqueId("unique_id")
               .build();
```

{% endtab %}
{% endtabs %}

These are the public methods available for OfferWallConfig.Builder class:

<table><thead><tr><th width="213">Public Methods</th><th>Description</th></tr></thead><tbody><tr><td>setUniqueId(String uniqueId)</td><td>Sets a unique id that will be used to identify the user uniquely. This will be sent back in the postback.</td></tr><tr><td>setLoaderBackgroundBitmap(Bitmap bitmap)</td><td>Accepts a bitmap and uses it as the background image for the loader and offerwall top banner.<br>Default: Black color image</td></tr><tr><td>setLoaderForegroundBitmap(Bitmap bitmap)</td><td>Accepts a bitmap and uses it as the foreground image for the loader and offerwall top banner.<br>Default: App icon</td></tr><tr><td>setFullscreenEnabled(Boolean isEnabled)</td><td>Sets if the offerwall should open in fullscreen mode or not. This can be used in apps or games where an immersive experience is needed.<br>Default: false</td></tr><tr><td>build()</td><td>Builds the config and returns OfferWallConfig instance</td></tr></tbody></table>

{% hint style="danger" %}
If a unique ID is not set, rewarding the user is not guaranteed.
{% endhint %}

### **3.3. Making the init call:**

Initialize the OfferWall SDK by calling the init function by passing the offer wall config.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
OfferWall.init(offerWallConfig, object : OfferWallInitListener {
   override fun onInitSuccess() {
   }
   override fun onInitFailed(error: InitError) {
   }
})
```

{% endtab %}

{% tab title="Java" %}

```java
OfferWall.init(offerWallConfig, new OfferWallInitListener() {
   @Override
   public void onInitSuccess() {

   }

   @Override
   public void onInitFailed(@NonNull InitError error) {

   }
});
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Make sure to handle Offerwall init failures properly as the init might fail in scenarios where the PubScale system detects a fraudulent environment.
{% endhint %}

{% hint style="info" %}
If you need to change any config after initializing the SDK, you should destroy and re-init the SDK.&#x20;

To destroy, call `OfferWall.destroy()`
{% endhint %}

## 4. Start the OfferWall

To start the offerwall, just call, `OfferWall.launch(Context, OfferWallListener);`

A listener can be set to listen for events fired by the Offer Wall.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import com.pubscale.sdkone.offerwall.OfferWall
import com.pubscale.sdkone.offerwall.models.OfferWallListener
import com.pubscale.sdkone.offerwall.models.Reward
..
..
..
val offerWallListener = object : OfferWallListener{

   override fun onOfferWallShowed() {
       Log.d("PSOfferwall", "Offer wall showed.")
   }

   override fun onOfferWallClosed() {
       Log.d("PSOfferwall", "Offer wall closed.")
   }

   override fun onRewardClaimed(reward: Reward) {
       Log.d("PSOfferwall", "Offer wall reward claimed.")
   }

   override fun onFailed(message: String) {
       Log.d("PSOfferwall", "onFailed: $message")
   }
}                 
```

{% endtab %}

{% tab title="Java" %}

```java
import com.pubscale.sdkone.offerwall.OfferWall
import com.pubscale.sdkone.offerwall.models.OfferWallListener
import com.pubscale.sdkone.offerwall.models.Reward
..
..
OfferWallListener offerWallListener = new OfferWallListener() {

   @Override
   public void onOfferWallShowed() {
       Log.d("PSOfferwall", "Offer wall showed.");
   }

   @Override
   public void onOfferWallClosed() {
       Log.d("PSOfferwall", "Offer wall closed.");
   }

   @Override
   public void onRewardClaimed(@NonNull Reward reward) {
       Log.d("PSOfferwall", "Offer wall reward claimed.");
   }

   @Override
   public void onFailed(@NonNull String message) {
       Log.d("PSOfferwall", "onFailed: " + message);
   }
};
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
onRewardClaimed callback gives you the reward amount and currency details.
{% endhint %}

To start the OfferWall, call the launch method of the OfferWall class.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import com.pubscale.sdkone.offerwall.OfferWall
import com.pubscale.sdkone.offerwall.models.OfferWallListener
..
..
OfferWall.launch(context, offerWallListener)            
```

{% endtab %}

{% tab title="Java" %}

```java
import com.pubscale.sdkone.offerwall.OfferWall
import com.pubscale.sdkone.offerwall.models.OfferWallListener
..
..
OfferWall.launch(context, offerWallListener);
```

{% endtab %}
{% endtabs %}

## 5. Setup S2S callbacks <a href="#id-3.-test-the-offerwall" id="id-3.-test-the-offerwall"></a>

Setup the S2S callbacks to get instant updates whenever the user gets the reward. You can use this callback to reward the user in your application. [Learn more.](https://pubscale.gitbook.io/offerwall-sdk/1.0.10/s2s-callback-configuration)

## 6. Test the OfferWall <a href="#id-3.-test-the-offerwall" id="id-3.-test-the-offerwall"></a>

{% hint style="info" %}
Please use the sandbox environment for testing purposes to get instant callbacks and rewards. To learn how to enable the Sandbox environment, [click here](https://pubscale.gitbook.io/offerwall-sdk/1.0.10/sandbox-environment/sandbox-environment).
{% endhint %}

Finally, To test the offerwall, build the application to an actual device. Check if you can launch the Offerwall and get the appropriate callbacks.
