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.
- Java
- Kotlin
RewardedAd rewardedAd = new RewardedAd(getActivity(), "Ad_Unit_ID");
RewardedAd rewardedAd = RewardedAd(requireActivity(), "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:
- Java
- Kotlin
rewardedAd.load(requestOptions)
rewardedAd.load(requestOptions)
Without RequestOptions
- Java
- Kotlin
rewardedAd.load()
rewardedAd.load()
Ad events
Register for Rewarded events
To recieve ad's lifecycle events regisger a listerner in RewardedAd
.
- Java
- Kotlin
public class RewardedAdFragment extends Fragment implements RewardedAdListener {
...
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
rewardedAd.setRewardedAdListener(this);
...
}
...
}
// set a rewarded ad listener
class RewardedAdFragment : Fragment(), RewardedAdListener {
...
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
...
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.
- Java
- Kotlin
@Override
public void onAdLoaded() {
Log.d(TAG, "Rewarded did load");
}
override fun 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.
- Java
- Kotlin
@Override
public void onAdFailedToLoad(Exception adsException) {
Log.e(TAG, "Rewarded did fail to load :" + adsException.toString());
}
override fun onAdFailedToLoad(adsException: Exception) {
Log.e(TAG, "Rewarded did fail to load :" + adsException.toString())
}
- onAdDisplayed(): will be called when Rewarded ad was shown.
- Java
- Kotlin
@Override
public void onAdDisplayed() {
Log.d(TAG, "Rewarded Did Shown");
}
override fun onAdDisplayed() {
Log.d(TAG, "Rewarded Did Shown")
}
- onAdFailedToDisplay(): will be called when Rewarded ad is failed to display.
- Java
- Kotlin
@Override
public void onAdFailedToDisplay(@NonNull Exception exception) {
Log.e(TAG, "Rewarded did fail :" + adsException.toString());
}
override fun onAdFailedToDisplay(@NonNull Exception exception)p pbgh {
Log.e(TAG, "Rewarded did fail :" + adsException.toString());
}
- onAdClicked(): will be called when user click the Rewarded ad.
- Java
- Kotlin
@Override
public void onAdClicked() {
Log.d(TAG, "Ad Clicked");
}
override fun onAdClicked() {
Log.d(TAG, "Ad Clicked")
}
- onAdDismissed(): will be called when Rewarded ad was dismissed.
- Java
- Kotlin
@Override
public void onAdDismissed() {
Log.d(TAG, "Rewarded disappear");
}
override fun onAdDismissed() {
Log.d(TAG, "Rewarded disappear")
}
- onEarnedReward(): will be called when user earned a reward.
- Java
- Kotlin
@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");
}
}
override fun onEarnedReward(reward: Reward?) {
if (reward != null) {
Log.d(
TAG,
"onEarnedReward, type: ${reward.type}, amount: ${reward.amount}"
)
} else {
Log.d(TAG, "onEarnedReward 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) :
- Java
- Kotlin
...
if (rewardedAd.isReady()) {
rewardedAd.show();
} else {
Log.d(TAG, "RewardedAd not ready ");
}
...
...
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.
- Java
- Kotlin
@Override
protected void onDestroy() {
if (rewardedAd != null) {
rewardedAd.destroy();
rewardedAd = null;
}
super.onDestroy();
}
override fun onDestroy() {
rewardedAd?.destroy()
rewardedAd = null
super.onDestroy()
}