Award-winning videos are not uploaded for the first time, but uploaded after

My application has a button to open the award-winning videos → when this button is pressed for the first time, this is the “Check your Internet connection” toast, when it gets the second or third time, it shows the video without problems

    MobileAds.initialize(getActivity(), getString(R.string.VID_App_ID));
    mRewardVideoAd = MobileAds.getRewardedVideoAdInstance(getActivity());
    mRewardVideoAd.loadAd(getString(R.string.VID_App_Unit_ID), new AdRequest.Builder()
            .addTestDevice(getString(R.string.TestDeviceID))
            .build());
    mRewardVideoAd.setRewardedVideoAdListener(this);
    loadRewardedVideoAd();   

Here are the methods used:

 private void loadRewardedVideoAd() {
        mRewardVideoAd.loadAd(getString(R.string.VID_App_Unit_ID), new AdRequest.Builder()
                .addTestDevice(getString(R.string.TestDeviceID))
                .build());
    }



   @OnClick(R.id.button_more_money)
    public void more_money() {
        if (mRewardVideoAd.isLoaded()) {
            mRewardVideoAd.show();
        } else
            { 
             Toast.makeText(getActivity(), "Check your internet connection", Toast.LENGTH_LONG).show();
            loadRewardedVideoAd();
               }

    }


    @Override
    public void onResume() {
        mRewardVideoAd.resume(getActivity());
        super.onResume();
        loadRewardedVideoAd();
    }

Edit: Resolved - It took some time and the solution was uploaded to onCreate () Thanks to Martin De Simone and Avi Levin

+4
source share
2 answers

Demanded videos take time to download, your code is fine, the first time you click on a video it loads, and then when you click, it’s possible that the video has already been downloaded.

- onAdLoaded, .

+1

, RV . , ~ 30- , .

SDK RewardedVideoAdListener, , . , AdMob.

:

  • RewardedVideoAdListener java
  • ( Toast , )

:

@Override
public void onRewarded(RewardItem reward) {
    Toast.makeText(this, "onRewarded! currency: " + reward.getType() + "  amount: " +
        reward.getAmount(), Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoAdLeftApplication() {
    Toast.makeText(this, "onRewardedVideoAdLeftApplication",
            Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoAdClosed() {
    Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
}

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

@Override
public void onRewardedVideoAdLoaded() {
    Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoAdOpened() {
    Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
}

@Override
public void onRewardedVideoStarted() {
    Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
}

: - isLoaded() , AdMob -, :

if (mAd.isLoaded()) {
    mAd.show();
}

Google AdMob doc

+1

Source: https://habr.com/ru/post/1682261/


All Articles