Kimi Chiu
Kimi Chiu

Reputation: 2173

AdMob RewardedVideoAd.loadAd always returns "failed to load ads, error code: 0"

I'm using firebase-ads:9.2.0 with API level 24.

And unity-ads aar module is imported by adding compile(name:'unity-ads', ext:'aar') to my build.gradle.

Everything goes fine if I choose to use UnityAds API directly.

But when I try to integrate unity-ads with AdMob like this:

    mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance( this );

    mRewardedVideoAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
        @Override
        public void onRewardedVideoAdLoaded() {
            logger.debug("onRewardedVideoAdLoaded");
        }

        @Override
        public void onRewardedVideoAdOpened() {
            logger.debug("onRewardedVideoAdOpened");
        }

        @Override
        public void onRewardedVideoStarted() {
            logger.debug("onRewardedVideoStarted");
        }

        @Override
        public void onRewardedVideoAdClosed() {
            logger.debug("onRewardedVideoAdClosed");
        }

        @Override
        public void onRewarded(RewardItem rewardItem) {
            logger.debug("onRewarded");
        }

        @Override
        public void onRewardedVideoAdLeftApplication() {
            logger.debug("onRewardedVideoAdLeftApplication");
        }

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

    AdRequest adRewardRequest = new AdRequest.Builder()
        .addTestDevice("E921B48960E16DA3ABD13C4AFB7052A4")
        .build();

    mRewardedVideoAd.loadAd( 
        getResources().getString(R.string.reward_ad_unit_id), 
        adRewardRequest );

It always returns

There was a problem getting an ad response. ErrorCode: 0
Failed to load ad: 0.

Is there anything I did it in the wrong way?

Or I just missed some steps?

Here is my AdMob page screenshot:

AdMob page

Upvotes: 9

Views: 15754

Answers (3)

PSN
PSN

Reputation: 2516

Usually this happens for newly created ads, so wait for an hour and try again.

public static final int ERROR_CODE_INTERNAL_ERROR

Something happened internally; for instance, an invalid response was received from the ad server.

Constant Value: 0

Source: Google Developers

Upvotes: 2

Kimi Chiu
Kimi Chiu

Reputation: 2173

Okay, I found solutions.

The first thing is that I didn't include adapters in my project.

I have to download the adpaters here: Third-party network adapters

And put it into the libs folder. These adapters are not included in the SDKs(if you download it from github).

Second, I have to remove this line out of my code.

.addTestDevice("E921B48960E16DA3ABD13C4AFB7052A4")

It seems like if the AdMob treat this device as a test device, there will be no any video ad to be downloaded(at least in my case).

Same thing happens if I choose to use the AVD, they force to show test ads on these emulators.

So I change to Genymotion, remove the addTestDevice() and then it works.

Upvotes: 6

leonz
leonz

Reputation: 1127

I'm using interstitial ads, but I believe it is the same problem. Google sometimes gives code that doesn't work, don't ask me why is that.

Add this after your mRewardedVideoAd.loadAd() method:

mRewardedVideoAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            //your code when Ad is loaded
            //you can show your ad immediately, but I don't suggest it
            if (mRewardedVideoAd.isLoaded()) {
                mRewardedVideoAd.show(); //this shows ad immediately
            }
        }

        @Override
        public void onAdClosed() {
        }
    });

Or you can set the AdListener, don't show it immediately, but rather make a new method:

public static void displayAd() {
    if (mRewardedVideoAd.isLoaded()) {
        mRewardedVideoAd.show();
    }
}

And this way, you can call this method from any activity, which shows the ad almost instantly (because it was already loaded), without the need to loading it again.

Upvotes: 1

Related Questions