Rewarded Video - pubnative/pubnative-hybid-android-sdk GitHub Wiki
Rewarded ads will be rendered using the HyBid SDK.
Requirements:
- Ad Zone Id from the PubNative Publisher Dashboard
Code sample
You can find a demo app with code samples for this type of integration here.
Create HyBidRewardedAd attribute in you activity or fragment
private HyBidRewardedAd mRewarded;
Request the ad
Create an instance of the rewarded ad object using the zone id and setting a listener. Use the load method to make an ad request.
private void loadRewardedVideo() {
mRewarded = new HyBidRewardedAd(this,"ZONE_ID", new HyBidRewardedAd.Listener() {
@Override
public void onRewardedLoaded() {
}
@Override
public void onRewardedLoadFailed(Throwable error) {
}
@Override
public void onRewardedOpened() {
}
@Override
public void onRewardedClosed() {
}
@Override
public void onRewardedClick() {
}
@Override
public void onReward() {
}
});
mRewarded.load();
}
Display the ad
After the ad is successfully retrieved from the server, the onRewardedLoaded callback will notify that the ad is ready to be displayed.
You can display the rewarded video as soon as it's loaded using after getting the callback. Use the show method to display the ad:
mRewarded = new HyBidRewardedAd(this,"ZONE_ID", new HyBidRewardedAd.Listener() {
@Override
public void onRewardedLoaded() {
mRewarded.show();
}
@Override
public void onRewardedLoadFailed(Throwable error) {
}
@Override
public void onRewardedOpened() {
}
@Override
public void onRewardedClosed() {
}
@Override
public void onRewardedClick() {
}
@Override
public void onReward() {
}
});
if you don't want to show the ad right away after being loaded, you can use the isReady method that returns a boolean stating if the ad has been loaded and is ready to be displayed.
if (mRewarded.isReady()) {
mRewarded.show();
}
Finally destroy the rewarded video when the activity or fragment are destroyed
@Override
public void onDestroy() {
if (mRewarded != null) {
mRewarded.destroy();
}
super.onDestroy();
}