Display rewarded ad on Android
Display a rewarded ad
val rewardedAd = AdropRewardedAd(context, "YOUR_UNIT_ID")
rewardedAd.rewardedAdListener = object : AdropRewardedAdListener {
override fun onAdReceived(ad: AdropRewardedAd) {
Log.d("Adrop", "rewarded ad received ${ad.unitId}")
ad.show()
}
override fun onAdFailedToReceive(ad: AdropRewardedAd, errorCode: AdropErrorCode) {
Log.d("Adrop", "failed to receive $errorCode")
}
override fun onAdFailedToShowFullScreen(ad: AdropRewardedAd, errorCode: AdropErrorCode) {
Log.d("Adrop", "failed to show full screen $errorCode")
}
...
}
rewardedAd.load()
...
// call show function when the ad needs to be displayed.
rewardedAd.show(activity) { type, amount ->
Log.d("ADROP", "earn handler $type, $amount")
}
AdropRewardedAd rewardedAd = new AdropRewardedAd(context, "YOUR_UNIT_ID");
rewardedAd.setRewardedAdListener(new AdropRewardedAdListener() {
@Override
public void onAdReceived(@NotNull AdropRewardedAd ad) {
Log.d("Adrop", "rewarded ad received " + ad.unitId);
ad.show();
}
@Override
public void onAdFailedToReceive(@NotNull AdropRewardedAd ad, @NotNull AdropErrorCode errorCode) {
Log.d("Adrop", "failed to received " + errorCode);
}
@Override
public void onAdFailedToShowFullScreen(@NotNull AdropRewardedAd ad, @NotNull AdropErrorCode errorCode) {
Log.d("Adrop", "failed to show full screen " + errorCode);
}
...
});
rewardedAd.load();
...
// call show function when the ad needs to be displayed.
rewardedAd.show(this, (type, amount) -> {
Log.d("ADROP", "rewarded ad reward handler, type: " + type + ", amount: " + amount);
return null;
});
Destroy
When you are done showing your AdropRewardedAd, you should destroy it so that the ad is properly garbage collected.
rewardedAd.destroy()
rewardedAd.destroy();
Last updated