Initialize CAS - cleveradssolutions/CAS-Android GitHub Wiki

:zap: Before you start
Make sure you have correctly Project setup.


Initialize MediationManager

In most cases, a casId is the same as your application package name.

  • package name uniquely identifies your app on the device and in the Google Play Store.
  • The package name value is case-sensitiv and is often referred to as an APPLICATION_ID.
  • Find your app's package name in your module (app-level) Gradle file, usually app/build.gradle (example package name: com.yourcompany.yourproject).
  • If you haven't created an CAS account and registered an app yet, now's a great time to do so at CAS.ai.
  • In a real app, it is important that you use your actual CAS manager ID.

[!IMPORTANT]
Do not initialize mediated advertising SDKs (CAS does that for you).
Not following this step will result in noticeable integration issues.

import com.cleversolutions.ads.*;
import com.cleversolutions.ads.android.CAS;

class MainApplication extends Application{

  @Override
  protected void onCreate() {
      super.onCreate();
      // Configure AdsSettings before initialize
      MediationManager manager = getAdManager();
  }

  public MediationManager getAdManager(){
    return CAS.buildManager()
       // Set your CAS ID
       .withCasId(BuildConfig.APPLICATION_ID)
       .withCompletionListener(config -> {
          String initErrorOrNull = config.getError();
          String userCountryISO2OrNull = config.getCountryCode();
          boolean protectionApplied = config.isConsentRequired();
          MediationManager manager = config.getManager();
       })
       // List Ad formats used in app
       .withAdTypes(AdType.Banner, AdType.Interstitial, AdType.Rewarded)
       // Use Test ads or live ads
       .withTestAdMode(isTestBuild)
       .initialize(this);
  }
}

Ads processing

CAS have functionality to limit the processing of specific AdType.
This can be useful when you need to improve application performance by turning off unused formats.
Or if you have determined that the user will no longer need to be shown ads, for example after purchase.

List the AdTypes that will be used in your application:

managerBuilder.withAdTypes(AdType.Banner, AdType.Interstitial, AdType.Rewarded);

🌟 Your choice helps us configuring mediation in the most effective way for you, depending on the chosen ad formats.

Also, the state can be changed after initialization using the following methods:

manager.setEnabled(AdType.Interstitial, false);
  • If processing is inactive then all calls to the selected ad type will fail with error AdError.CODE_MANAGER_IS_DISABLED.
  • The state will not be saved between sessions.
  • ⚠️ Turning off the processing leads to the complete destruction of the ready ads from memory. And reactivation after destruction requires a new load of ads to memory.

Retrieve the Version Number

To programmatically retrieve the SDK version number at runtime, CAS provides the following method:

String sdkVersion = CAS.getSDKVersion();

🔗 Done! What’s Next?