Rewarded
RewardedRequest
Setup RewardedRequest builder
To create a RewardedRequest
instance, you need to create a RewardedRequest.Builder
instance, set all the necessary parameters and call build
on it.
RewardedRequest.Builder rewardedRequestBuilder = new RewardedRequest.Builder()
.setTargetingParams(...) // Set TargatingParams instance
.setPriceFloorParams(...) // Set price floor parameters
.setSessionAdParams(...) // Set SessionAdParams instance
.setLoadingTimeOut(...) // Set loading timeout in milliseconds
.setPlacementId(...) // Set placement id
val rewardedRequestBuilder = RewardedRequest.Builder()
.setTargetingParams(...) // Set TargatingParams instance
.setPriceFloorParams(...) // Set price floor parameters
.setSessionAdParams(...) // Set SessionAdParams instance
.setLoadingTimeOut(...) // Set loading timeout in milliseconds
.setPlacementId(...) // Set placement id
Set AdRequestListener
Set the RewardedRequest.AdRequestListener
instance to theRewardedRequest.Builder
instance.
rewardedRequestBuilder.setListener(new RewardedRequest.AdRequestListener() {
/**
* Called when RewardedRequest was requested successfully
*
* @param request - RewardedRequest instance
* @param auctionResult - AuctionResult info
*/
@Override
public void onRequestSuccess(@NonNull RewardedRequest request,
@NonNull AuctionResult auctionResult) {
}
/**
* Called when RewardedRequest request failed
*
* @param request - RewardedRequest instance
* @param error - BMError with additional info about error
*/
@Override
public void onRequestFailed(@NonNull RewardedRequest request,
@NonNull BMError error) {
}
/**
* Called when RewardedRequest expired
*
* @param request - RewardedRequest instance
*/
@Override
public void onRequestExpired(@NonNull RewardedRequest request) {
}
});
rewardedRequestBuilder.setListener(object : RewardedRequest.AdRequestListener {
/**
* Called when RewardedRequest was requested successfully
*
* @param request - RewardedRequest instance
* @param auctionResult - AuctionResult info
*/
override fun onRequestSuccess(request: RewardedRequest,
auctionResult: AuctionResult) {
}
/**
* Called when RewardedRequest request failed
*
* @param request - RewardedRequest instance
* @param error - BMError with additional info about error
*/
override fun onRequestFailed(request: RewardedRequest,
error: BMError) {
}
/**
* Called when RewardedRequest expired
*
* @param request - RewardedRequest instance
*/
override fun onRequestExpired(request: RewardedRequest) {
}
})
Note
AdRequestListener
callbacks are delivered on the background thread, not the main one.
Build RewardedRequest
When all the necessary parameters are set, call build
on the RewardedRequest.Builder
instance:
RewardedRequest rewardedRequest = rewardedRequestBuilder.build();
val rewardedRequest = rewardedRequestBuilder.build()
Keep ad request
You need to keep reference to
RewardedRequest
before callingRewardedRequest#request
, otherwise, it is possible it will be cleared by Garbage Collector and callbacks wonβt be triggered.
Request RewardedRequest
When you need to request an ad and get an AuctionResult
, call request
on the RewardedRequest
instance.
rewardedRequest.request(...);
rewardedRequest.request(...)
When you made an in-house meditation and you decided that an advertisement from BidMachine will be shown - call
rewardedRequest.notifyMediationWin
, if BidMachine lost in mediation - callrewardedRequest.notifyMediationLoss
Destroy RewardedRequest
Destroy the RewardedRequest
instance if you don't need it anymore.
rewardedRequest.destroy();
rewardedRequest.destroy()
Don't destroy the
RewardedRequest
instance, if it will be used for load theRewardedAd
instance or if theRewardedAd
instance loaded with theRewardedRequest
instance has not been shown yet.Otherwise, ad will not work correctly, which can affect a lower display rate, fill rate, rendering errors, and as a result - lower revenue.
RewardedAd
Load RewardedAd
When you would like to load and display requested Ads:
- Make sure that the
RewardedRequest
instance haveAuctionResult
. It's mean ads requested successfully.
rewardedRequest.getAuctionResult() != null
rewardedRequest.auctionResult != null
- Make sure that the
RewardedRequest
instance not expired.
!rewardedRequest.isExpired()
!rewardedRequest.isExpired
Before execute load
on the RewardedAd
instance set the RewardedListener
instance:
RewardedAd rewardedAd = new RewardedAd(...);
rewardedAd.setListener(new RewardedListener() {
/**
* Called when Ad was loaded and ready to be displayed
*
* @param ad - RewardedAd instance
*/
@Override
public void onAdLoaded(@NonNull RewardedAd ad) {
}
/**
* Called when Ad failed to load
*
* @param ad - RewardedAd instance
* @param error - BMError with additional info about error
*/
@Override
public void onAdLoadFailed(@NonNull RewardedAd ad,
@NonNull BMError error) {
}
/**
* Called when Ad Impression has been tracked
*
* @param ad - RewardedAd instance
*/
@Override
public void onAdImpression(@NonNull RewardedAd ad) {
}
/**
* Called when Ad show failed
*
* @param ad - RewardedAd instance
* @param error - BMError with additional info about error
*/
@Override
public void onAdShowFailed(@NonNull RewardedAd ad,
@NonNull BMError error) {
}
/**
* Called when Ad has been clicked
*
* @param ad - RewardedAd instance
*/
@Override
public void onAdClicked(@NonNull RewardedAd ad) {
}
/**
* Called when Rewarded Ad was completed (e.g.: the video has been played to the end).
* You can use this event to reward user
*
* @param ad - RewardedAd instance
*/
@Override
public void onAdRewarded(@NonNull RewardedAd ad) {
}
/**
* Called when Ad was closed (e.g - user click close button)
*
* @param ad - RewardedAd instance
* @param finished - Value for indicated, if ads was finished (e.g - video playing finished)
*/
@Override
public void onAdClosed(@NonNull RewardedAd ad,
boolean finished) {
}
/**
* Called when Ad expired
*
* @param ad - RewardedAd instance
*/
@Override
public void onAdExpired(@NonNull RewardedAd ad) {
}
});
rewardedAd.load(rewardedRequest);
val rewardedAd = RewardedAd(...)
rewardedAd.setListener(object : RewardedListener {
/**
* Called when Ad was loaded and ready to be displayed
*
* @param ad - RewardedAd instance
*/
override fun onAdLoaded(ad: RewardedAd) {
}
/**
* Called when Ad failed to load
*
* @param ad - RewardedAd instance
* @param error - BMError with additional info about error
*/
override fun onAdLoadFailed(ad: RewardedAd,
error: BMError) {
}
/**
* Called when Ad Impression has been tracked
*
* @param ad - RewardedAd instance
*/
override fun onAdImpression(ad: RewardedAd) {
}
/**
* Called when Ad show failed
*
* @param ad - RewardedAd instance
* @param error - BMError with additional info about error
*/
override fun onAdShowFailed(ad: RewardedAd,
error: BMError) {
}
/**
* Called when Ad has been clicked
*
* @param ad - RewardedAd instance
*/
override fun onAdClicked(ad: RewardedAd) {
}
/**
* Called when Rewarded Ad was completed (e.g.: the video has been played to the end).
* You can use this event to reward user
*
* @param ad - RewardedAd instance
*/
override fun onAdRewarded(@NonNull RewardedAd ad) {
}
/**
* Called when Ad was closed (e.g - user click close button)
*
* @param ad - RewardedAd instance
* @param finished - Value for indicated, if ads was finished (e.g - video playing finished)
*/
override fun onAdClosed(ad: RewardedAd,
finished: Boolean) {
}
/**
* Called when Ad expired
*
* @param ad - RewardedAd instance
*/
override fun onAdExpired(ad: RewardedAd) {
}
})
rewardedAd.load(rewardedRequest)
Use onAdLoaded
callback to determine the possibility of displaying
Show RewardedAd
Before displaying, check if the RewardedAd
instance can be displayed:
rewardedAd.canShow();
rewardedAd.canShow()
To display the RewardedAd
instance, you just need to execute show
.
rewardedAd.show();
rewardedAd.show()
Destroy RewardedAd
After ad was successful shown and no longer needed, it can be destroyed.
rewardedAd.destroy();
rewardedAd.destroy()
Sample
You can find code examples written in Java and Kotlin: Github Rewarded
Updated 12 months ago