rewarded video google admob


private RewardedVideoAd AdMobrewardedVideoAd;

// AdMob Rewarded Video Ad Id
private String AdId
= "ca-app-pub-3940256099942544/5224354917";

void loadRewardedVideoAd()
{
// initializing RewardedVideoAd Object
// RewardedVideoAd Constructor Takes Context as its
// Argument
AdMobrewardedVideoAd
= MobileAds
.getRewardedVideoAdInstance(getApplicationContext());

// Rewarded Video Ad Listener
AdMobrewardedVideoAd.setRewardedVideoAdListener(
new RewardedVideoAdListener() {
@Override
public void onRewardedVideoAdLoaded()
{
// Showing Toast Message
Toast.makeText(getApplicationContext(),
"onRewardedVideoAdLoaded",
Toast.LENGTH_SHORT)
.show();
}

@Override
public void onRewardedVideoAdOpened()
{
// Showing Toast Message
Toast
.makeText(getApplicationContext(),
"onRewardedVideoAdOpened",
Toast.LENGTH_SHORT)
.show();
}

@Override
public void onRewardedVideoStarted()
{
// Showing Toast Message
Toast
.makeText(getApplicationContext(),
"onRewardedVideoStarted",
Toast.LENGTH_SHORT)
.show();
}

@Override
public void onRewardedVideoAdClosed()
{
// Showing Toast Message
Toast
.makeText(getApplicationContext(),
"onRewardedVideoAdClosed",
Toast.LENGTH_SHORT)
.show();
}

@Override
public void onRewarded(
RewardItem rewardItem)
{
// Showing Toast Message
Toast
.makeText(getApplicationContext(),
"onRewarded",
Toast.LENGTH_SHORT)
.show();
}

@Override
public void
onRewardedVideoAdLeftApplication()
{
// Showing Toast Message
Toast
.makeText(getApplicationContext(),
"onRewardedVideoAdLeftApplication",
Toast.LENGTH_SHORT)
.show();
}

@Override
public void onRewardedVideoAdFailedToLoad(
int i)
{
// Showing Toast Message
Toast
.makeText(
getApplicationContext(),
"onRewardedVideoAdFailedToLoad",
Toast.LENGTH_SHORT)
.show();
}

@Override
public void onRewardedVideoCompleted()
{
// Showing Toast Message
Toast
.makeText(
getApplicationContext(),
"onRewardedVideoCompleted",
Toast.LENGTH_SHORT)
.show();
}
});

// Loading Rewarded Video Ad
AdMobrewardedVideoAd.loadAd(
AdId, new AdRequest.Builder().build());
}

public void showRewardedVideoAd()
{
// Checking If Ad is Loaded or Not
if (AdMobrewardedVideoAd.isLoaded()) {
// showing Video Ad
AdMobrewardedVideoAd.show();
}
else {
// Loading Rewarded Video Ad
AdMobrewardedVideoAd.loadAd(
AdId, new AdRequest.Builder().build());
}
}



// In onCreate()
MobileAds.initialize(this);
loadRewardedVideoAd();


// where you want to show ad

showRewardedVideoAd();

Did you find this article useful?