Rewarded Ads - cleveradssolutions/CAS-Android GitHub Wiki

:zap: Before you start
Make sure you have correctly Initialize CAS.


This guide explains how to integrate rewarded video ads into an Android app.

Load an ad

[!NOTE]
By default, the auto-load ads mode is used and a load method does not need to be called. Call manual load ad before each show if you use LoadingManagerMode.Manual only.

Manual load Rewarded ads.

manager.loadRewardedAd();

You can get a callback for the successful loading of the ads:

manager.getOnAdLoadEvent().add(new AdLoadCallback() {  
    @Override  
    public void onAdLoaded(@NonNull AdType type) {  
        if (type == AdType.Rewarded) {  
            // Rewarded loaded  
        }  
    }  
  
    @Override  
    public void onAdFailedToLoad(@NonNull AdType type, @Nullable String error) {  
        if (type == AdType.Rewarded) {  
            // Rewaeded failed to load with error  
        }  
    }  
});

Check the ad availability

You can ask for the ad availability directly by calling the following function:

boolean adLoaded = manager.isRewardedAdReady();

Ad Callback

The AdCallback handles events related to displaying your Rewarded ad.

AdCallback callback = new AdCallback() {  
    @Override  
    public void onShown(@NonNull AdStatusHandler ad) {  
        // Called when ad is shown.
    }  
  
    @Override  
    public void onShowFailed(@NonNull String message) {  
        // Called when ad fails to show. 
    }  
  
    @Override  
    public void onClicked() {  
        // Called when a click is recorded for an ad.  
    }  
  
    @Override  
    public void onComplete() {  
        // Called when ad is completed
        Log.d("Sample", "The user earned the reward.");
    }  
  
    @Override  
    public void onClosed() {  
        // Called when ad is dismissed
    }  
};

[!WARNING]
When an error occurs during ad impression, executed the onShowFailed() only.
onClosed() in this case will not be executed, since the impression is not considered successful.

[!NOTE]
Read more about event onShown with Impression level data.

Show the ad

Before displaying a rewarded ad to users, you must present the user with an explicit choice to view rewarded ad content in exchange for a reward. Rewarded ads must always be an opt-in experience.

The showRewardedAd() method requires Activity and AdCallback instances as arguments.

  • activity The Activity instance should be the activity from which the rewarded ad is presented.
  • callback The callback for Rewarded ad events.
    When you show a rewarded ad, you will use an AdCallback object to handle reward events onComplete().
manager.showRewardedAd(activity, callback);

Allow Interstitial ads

Sometimes a situation occurs when filling Rewarded ads is not enough, in this case, you can allow the display of Interstitial ads to receiving a reward in any case. This option will compare ad cost and serve regular interstitial ads when rewarded video ads are expected to generate less revenue.
Interstitial Ads does not require to watch the video to the end, but the AdCallback.onComplete() event will be invoked in any case.
Enabled by default.

CAS.getSettings().setAllowInterstitialAdsWhenVideoCostAreLower(true);

Muted Ad sounds

Indicates if the application’s audio is muted. Affects initial mute state for all ads.
Use this method only if your application has its own volume controls.

CAS.getSettings().setMutedAdSounds(true);

🔗 Done! What’s Next?