Skip to content

Advanced Rewarded API

Warning

This is the documentation for the Advanced API. Most developers should use our Simplified API, which comes with several built-in features such as:

  • automatic ad loading

  • retries for failed requests

See the documentation for the Simplified API here:

Rewarded ads (also known as rewarded video ads) are a fullscreen format, but unlike interstitials, the user is incentivized to watch its entire duration (usually 30 seconds) in order to get an in-app reward, such as in-game currency, extra lives or hints to pass a level.

The onEarnedReward callback will be triggered by the adapted network, signaling that you can give the user their reward. If the user decides to skip the ad, this callback will not be called.

Create a Rewarded instance

val rewarded = Rewarded.create(
    activity = yourActivity,
    placementId = "<placement-id>"
)
Rewarded rewarded = Rewarded.create(
    this,
    "<placement-id>"
);

Register ad callbacks

rewarded.listener = object : Rewarded.Listener {

    // Load callbacks

    override fun onLoaded(loadResult: LoadResult) {
        Log.d("Rewarded", "Loaded!")
    }

    override fun onFailedToLoad(loadError: LoadError, loadResult: LoadResult?) {
        Log.d("Rewarded", "Failed to load. Reason: ${loadError.message}")
    }

    // Show callbacks

    override fun onFailedToShow(showError: ShowError) {
        // If you need to resume your app's flow, make sure to do it here and in the onDismissed callback
        Log.d("Rewarded", "Failed to show. Reason: ${showError.message}")
    }

    override fun onImpression(impressionData: ImpressionData) {
        Log.d("Rewarded", "Impression with revenue: ${impressionData.revenue}")
    }

    override fun onShowed() {
        Log.d("Rewarded", "Was shown!")
    }

    override fun onDismissed() {
        // If you need to resume your app's flow, make sure to do it here and in the onFailedToShow callback
        Log.d("Rewarded", "Was dismissed!")
    }

    override fun onEarnedReward() {
        Log.d("Rewarded", "Earned reward!")
    }
}
rewarded.setListener(new Rewarded.Listener() {

    @Override
    public void onPrebiddingFinished(@NonNull PrebiddingResults result) {
        Log.d("RewardedSample", "Prebidding finished");
    }

    @Override
    public void onLoaded(@NonNull LoadResult loadResult) {
        Log.d("RewardedSample", "Loaded!");
    }

    @Override
    public void onFailedToLoad(@NonNull LoadError loadError, LoadResult loadResult) {
        Log.d("RewardedSample", "Failed to load. Reason: " + loadError.getMessage());
    }

    @Override
    public void onFailedToShow(@NonNull ShowError showError) {
        // If you need to resume your app's flow, make sure to do it here and in the onDismissed callback
        Log.d("RewardedSample", "Failed to show. Reason: " + showError.getMessage());
    }

    @Override
    public void onImpression(@NonNull ImpressionData impressionData) {
        Log.d("RewardedSample", "Impression with revenue: " + impressionData.getRevenue());
    }

    @Override
    public void onShowed() {
        Log.d("RewardedSample", "Was shown!");
    }

    @Override
    public void onClicked() {
        Log.d("Rewarded", "Was clicked!");
    }

    @Override
    public void onDismissed() {
        // If you need to resume your app's flow, make sure to do it here and in the onFailedToShow callback
        Log.d("RewardedSample", "Was dismissed!");
    }

    @Override
    public void onEarnedReward() {
        Log.d("RewardedSample", "Earned reward!");
    }
});

Load an ad

rewarded.load()
rewarded.load();

Load an ad (with custom properties)

rewarded.load(
    buildCustomProperties { 
        addString("game_mode", "classic")
    }
)
rewarded.load(
    new CustomProperties.Builder()
            .addString("game_mode", "classic")
            .build()
);

Show an ad

if (rewarded.isReady) {
    yourActivity.runOnUiThread {
        rewarded.show(yourActivity, "rewarded-ad-space")
    }
}
if (rewarded.isReady()) {
    yourActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            rewarded.show(yourActivity, "rewarded-ad-space");
        }
    });
}

Dispose an ad

rewarded.destroy()
rewarded.destroy();

Code example

RewardedSample.kt
import android.os.Bundle
import android.util.Log
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.etermax.xmediator.core.api.Rewarded
import com.etermax.xmediator.core.api.entities.ImpressionData
import com.etermax.xmediator.core.api.entities.LoadError
import com.etermax.xmediator.core.api.entities.LoadResult
import com.etermax.xmediator.core.api.entities.ShowError
import com.example.myapp.R

class RewardedSample : AppCompatActivity() {

    private var rewarded: Rewarded? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_rewarded)

        findViewById<Button>(R.id.button_load).setOnClickListener {
            Log.d("RewardedSample", "Load button clicked")

            // Dispose previous rewarded instance
            rewarded?.destroy()

            // Create an rewarded instance
            rewarded = Rewarded.create(
                activity = this,
                placementId = "<placement-id>"
            )

            // Setup callbacks
            rewarded?.listener = object : Rewarded.Listener {
                override fun onLoaded(loadResult: LoadResult) {
                    Log.d("RewardedSample", "Loaded!")
                }

                override fun onFailedToLoad(loadError: LoadError, loadResult: LoadResult?) {
                    Log.d("RewardedSample", "Failed to load. Reason: ${loadError.message}")
                }

                override fun onFailedToShow(showError: ShowError) {
                    // If you need to resume your app's flow, make sure to do it here and in the onDismissed callback
                    Log.d("RewardedSample", "Failed to show. Reason: ${showError.message}")
                }

                override fun onImpression(impressionData: ImpressionData) {
                    Log.d("RewardedSample", "Impression with revenue: ${impressionData.revenue}")
                }

                override fun onShowed() {
                    Log.d("RewardedSample", "Was shown!")
                }

                override fun onDismissed() {
                    // If you need to resume your app's flow, make sure to do it here and in the onFailedToShow callback
                    Log.d("RewardedSample", "Was dismissed!")
                }

                override fun onEarnedReward() {
                    Log.d("RewardedSample", "Earned reward!")
                }
            }

            // Request an ad
            rewarded?.load()
        }

        findViewById<Button>(R.id.button_is_ready).setOnClickListener {
            Log.d("RewardedSample", "Check Is Ready button clicked")
            val isReady = rewarded?.isReady
            Log.d("RewardedSample", "rewarded.isReady = $isReady")
        }

        findViewById<Button>(R.id.button_show).setOnClickListener {
            Log.d("RewardedSample", "Show button clicked")
            this.runOnUiThread {
                rewarded?.show(this)
            }
        }
    }

}