Aller au contenu principal
Version: 5.x.x

Rewarded Ads

Overview

RewardedAd that will serve to deliver rewarded video ads which are a full screen experience where users opt-in to view a video ad in exchange for something of value, such as virtual currency, in-app items, exclusive content, and more. The ad experience is 15-30 second non-skippable and contains an end card with a call to action. Upon completion of the full video, you will receive a callback to grant the suggested reward to the user.

Before You Start. Make sure that you have correctly integrated the MNG SDK into your application. Integration is outlined here.

Create a Rewarded Ad

In order to use the rewarded ad feature you have to instantiate the RewardedAd class.

RewardedAd rewardedAd = new RewardedAd(getActivity(), "Ad_Unit_ID");

Load a Rewarded Ad

Note: Make all calls to the BlueStack SDK on the main thread.

With RequestOptions

To request a rewarded ad using RequestOptions, provide an instance of RequestOptions in the RewardedAd's load method:

rewardedAd.load(requestOptions)

Without RequestOptions

rewardedAd.load()

Ad events

Register for Rewarded events

To recieve ad's lifecycle events regisger a listerner in RewardedAd.

public class RewardedAdFragment extends Fragment implements RewardedAdListener {
...
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
rewardedAd.setRewardedAdListener(this);
...
}
...
}

Implement Rewarded events

The SDK will notify your Listener of all possible events listed below :

  • onAdLoaded(): will be called by the SDK when your Rewarded ad is ready.
@Override
public void onAdLoaded() {
Log.d(TAG, "Rewarded did load");
}
  • onAdFailedToLoad(): will be called when all ads servers fail. it will return the error of the last called ad server.
@Override
public void onAdFailedToLoad(Exception adsException) {
Log.e(TAG, "Rewarded did fail to load :" + adsException.toString());
}
  • onAdDisplayed(): will be called when Rewarded ad was shown.
@Override
public void onAdDisplayed() {
Log.d(TAG, "Rewarded Did Shown");
}
  • onAdFailedToDisplay(): will be called when Rewarded ad is failed to display.
@Override
public void onAdFailedToDisplay(@NonNull Exception exception) {
Log.e(TAG, "Rewarded did fail :" + adsException.toString());
}
  • onAdClicked(): will be called when user click the Rewarded ad.
@Override
public void onAdClicked() {
Log.d(TAG, "Ad Clicked");
}
  • onAdDismissed(): will be called when Rewarded ad was dismissed.
@Override
public void onAdDismissed() {
Log.d(TAG, "Rewarded disappear");
}
  • onEarnedReward(): will be called when user earned a reward.
    @Override
public void onEarnedReward(@Nullable Reward reward) {
if (reward != null) {

Log.d("TAG", "onVideoRewarded, type: " + reward.getType() + " , amount: " + reward.getAmount());
} else {

Log.d("TAG", "onVideoRewarded with no reward object");
}
}

Show Rewarded Ad

To check if the rewarded is ready to be shown, you must call isReady() and show() in order to display the ad (in case of success) :

...
if (rewardedAd.isReady()) {
rewardedAd.show();
} else {
Log.d(TAG, "RewardedAd not ready ");
}
...

Destroying Rewarded Ad

When you have finished your ads plant you must free the memory.

@Override
protected void onDestroy() {
if (rewardedAd != null) {
rewardedAd.destroy();
rewardedAd = null;
}
super.onDestroy();
}