2

I am using https://github.com/floatinghotpot/cordova-admob-pro in my phonegap application.

For interstitial and banner I am using

AdMob.showInterstitial();

AdMob.showBanner(getSelectedPosition());

is working correctly. Now I am trying to display the Reward video. Firstly I have prepared the Reward video by

AdMob.prepareRewardVideoAd({adId: admobid.reward, autoShow: false}); 

Then I am trying to show it

AdMob.showRewardVideoAd();

But the video is not displaying, The method showRewardVideoAd() is my guess w.r.t. showInterstitial(), In documentation I have not found any method as AdMob.showRewardVideoAd().

What is the correct method, How should I display it ? please help

Jitesh Prajapati
  • 2,533
  • 4
  • 29
  • 51
mujaffars
  • 1,395
  • 2
  • 15
  • 35

3 Answers3

0

I am not sure, but maybe you should wait for the video to be prepared before calling the showRewardVideoAd. Try to call that function from inside the success callback of prepareRewardVideoAd.

Also, are you using "Admob." before the function calls? I think it is needed.

Dmitriy
  • 5,525
  • 12
  • 25
  • 38
0

Related one:

Being new, I came to this page in the morning and had no luck with -pro module
so, I shifted to -free module
that is, cordova-plugin-admob-free

I did several mistakes, but finally solved it, and wrote a github page here, now it works fine:
https://github.com/manoharreddyporeddy/everyday-solutions/blob/master/display-ads-on-android-using-admob.js

Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
-1

All you need to do is implement all required methods like onResume, onPause.

Look at my activity class:

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.reward.RewardItem;
import com.google.android.gms.ads.reward.RewardedVideoAd;
import com.google.android.gms.ads.reward.RewardedVideoAdListener;

public class AdActivity extends AppCompatActivity implements RewardedVideoAdListener {

    private RewardedVideoAd mRewardedVideoAd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ad);

        // Use an activity context to get the rewarded video instance.
        mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
        mRewardedVideoAd.setRewardedVideoAdListener(this);
        requestNewRewardVideo();
    }

    protected void onResume() {
        super.onResume();
        mRewardedVideoAd.resume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        mRewardedVideoAd.pause(this);
    }

    @Override
    public void onDestroy() {
        mRewardedVideoAd.destroy(this);
        super.onDestroy();
    }

    private void requestNewRewardVideo() {
        //load rewared video
        mRewardedVideoAd.loadAd("ca-app-pub-xxxxxxxxxxxxxxxxxx",
                new AdRequest.Builder().build());

    }

    @Override
    public void onRewardedVideoAdLoaded() {
        mRewardedVideoAd.show();
    }

    @Override
    public void onRewardedVideoAdOpened() {

    }

    @Override
    public void onRewardedVideoStarted() {

    }

    @Override
    public void onRewardedVideoAdClosed() {
        //request for new reward video
        requestNewRewardVideo();
    }

    @Override
    public void onRewarded(RewardItem rewardItem) {
        // reward your user here
    }

    @Override
    public void onRewardedVideoAdLeftApplication() {

    }

    @Override
    public void onRewardedVideoAdFailedToLoad(int i) {

    }
}

app build.gradle

implementation 'com.google.android.gms:play-services-ads:11.4.2'

display ads when Button clicked:

if (mRewardedVideoAd.isLoaded()) {
                mRewardedVideoAd.show();
            }
Pankaj Kant Patel
  • 2,050
  • 21
  • 27