Rewarded Video

Rewarded video interstitials are full-screen visuals that appear inside your application.

1. Prepare to reward the user

Next, you will need to override the TMAdListener class to receive callbacks on rewarded video adverts. Create a new file and implement it like so:

public class RewardedVideoListener extends TMAdListener {

    @Override
    public void didVerify(TDReward reward) {
        Log.i("MEDIATION-SAMPLE", String.format(Locale.ENGLISH, "didVerify: ID: %s, Tag: %s. Reward: %s. Value: %f. Valid: %b. Custom Json: %s", reward.getId(), reward.getTag(), reward.getName(), reward.getValue(), reward.isValid(), reward.getCustom_json().toString()));
    }
}

When the rewarded video has finished playing, the didVerify listener is triggered, and the user receives the reward.

For a full list of rewarded video listeners we support, see our Advanced page.

2. Load the rewarded video

To load a rewarded video, we recommend you load them once the Tapdaq SDK has initialised.

Go back to the TapdaqInitListener you created in the Quickstart guide, and add a call to load the rewarded video, like so:

public class TapdaqInitListener extends TMInitListener {

    @Override
    public void didInitialise() {
        super.didInitialise();
        // Ads may now be requested
        Tapdaq.getInstance().loadRewardedVideo(<CurrentActivity>,  "my_rewarded_tag", new RewardedVideoListener());
    }

}

3. Display the rewarded video

We then need to display the rewarded ad to the user when they perform some action, for example tapping a button.

boolean isReady = Tapdaq.getInstance().isRewardedVideoReady("my_rewarded_tag");

if (isReady) {
    Tapdaq.getInstance().showRewardedVideo(<CurrentActivity>, "my_rewarded_tag", new RewardedVideoListener());
} else {
  // Do something else
}

If you want to check a rewarded video is loaded before displaying a button the user would tap to see the reward, implement the following to the RewardedVideoListener you created earlier:

Note: TDReward.eventId is a unique identifier for every reward given to a user.

public class RewardedVideoListener extends TMAdListener {

    @Override
    public void didLoad() {
        // Rewarded video is loaded, enable your rewarded video button
    }

    @Override
    public void didVerify(TDReward reward) {
        Log.i("MEDIATION-SAMPLE", String.format(Locale.ENGLISH, "didVerify: ID: %s, Tag: %s. Reward: %s. Value: %f. Valid: %b. Custom Json: %s", reward.getId(), reward.getTag(), reward.getName(), reward.getValue(), reward.isValid(), reward.getCustom_json().toString()));
    }

}

Build and run your application to test the advert displays correctly.

4. Load another rewarded video on close

If you wish to load another rewarded video after you have shown one, implement one of the following options:

A. Auto Reload all Ads

To auto reload all ads using the same placement tag set the global config before initialising, like so:

TapdaqConfig config = new TapdaqConfig(this);
config.setAutoReloadAds(true);

B. Implement Override

When creating an ad listener, create a custom constructor and store the placement tag, then override didClose() and call load for the same type and placement tag.

private class AdListener extends TMAdListener {
        private String mTag;

        AdListener(String tag) {
            mTag = tag;
        }

        @Override
        public void didClose() {
            Tapdaq.getInstance().loadRewardedVideo(<CurrentActivity>, mTag, this);
        }
    }

Server Side Callbacks

Tapdaq SDK triggers server-side callbacks when a reward is provided, along with the client side didVerify callback.

Optionally you can add a Hashed User Id to the callback to identify the user to reward.

Need help?

If you are having any problems integrating, feel free to contact us on [email protected] and we will be more than happy to help.

What's next?

Now that you have successfully integrated a rewarded video into your app, what would you like to do next?