Android

The Chartboost SDK’s delegate methods allow you to exercise a greater degree of control over your integration. For example, you can:
  • Log debug messages when your game attempts to load an interstitial.
  • Prevent ads from showing the first time a user plays your game.
  • Determine whether a user has clicked an ad or just closed it – and react accordingly.
  • Prevent an interstitial page appearing when and where it would interfere with your game.
You can view the Chartboost Android SDK methods at your disposal in the documentation located in the doc folder included with your Android SDK download. You can see many of these methods in use in the sample project included in the package.  
▲ Back to top

Click here to view Android configuration methods.  
▲ Back to top

Before using any delegate functions, set the Chartboost delegate in your activity’s onCreate() method, like so:
Chartboost.setDelegate(YourDelegateObject);
  After that, initiate the delegate object and declare the delegate methods as follows:
private ChartboostDelegate YourDelegateObject = new ChartboostDelegate() {
    // Declare delegate methods here, see CBSample project for examples
};
 
▲ Back to top

CBImpressionError objects passed as parameters in delegate method calls include an adID property.
This is a string that uniquely identifies a cached ad. It might help when working with Chartboost to identify faulty creatives.
▲ Back to top

// Called before requesting an interstitial via the Chartboost API server.
public boolean shouldRequestInterstitial(String location)

// Called before an interstitial will be displayed on the screen.
public boolean shouldDisplayInterstitial(String location)

// Called after an interstitial has been displayed on the screen.
public void didDisplayInterstitial(String location)

// Called after an interstitial has been loaded from the Chartboost API
// servers and cached locally.
public void didCacheInterstitial(String location)

// Called after an interstitial has attempted to load from the Chartboost API
// servers but failed.
public void didFailToLoadInterstitial(String location, CBImpressionError error)

// Called after an interstitial has been dismissed.
public void didDismissInterstitial(String location)

// Called after an interstitial has been closed.
public void didCloseInterstitial(String location)

// Called after an interstitial has been clicked.
public void didClickInterstitial(String location)
Don’t make cache or show calls inside didFailToLoad delegates or the universe will implode.
 
▲ Back to top

// Called before a rewarded video will be displayed on the screen.
public boolean shouldDisplayRewardedVideo(String location)

// Called after a rewarded video has been displayed on the screen.
public void didDisplayRewardedVideo(String location)

// Called after a rewarded video has been loaded from the Chartboost API
// servers and cached locally.
public void didCacheRewardedVideo(String location)

// Called after a rewarded video has attempted to load from the Chartboost API
// servers but failed.
public void didFailToLoadRewardedVideo(String location, CBImpressionError error)

// Called after a rewarded video has been dismissed.
public void didDismissRewardedVideo(String location)

// Called after a rewarded video has been closed.
public void didCloseRewardedVideo(String location)

// Called after a rewarded video has been clicked.
public void didClickRewardedVideo(String location)

// Called after a rewarded video has been viewed completely and user is eligible for reward.
public void didCompleteRewardedVideo(String location, int reward)

// Implement to be notified of when a video will be displayed on the screen for
// a given CBLocation. You can then do things like mute effects and sounds.
public void willDisplayVideo(String location)
Don’t make cache or show calls inside didFailToLoad delegates or the universe will implode.
 
▲ Back to top

// Called if a click is registered by the app, but the user is not forwarded to the App Store.
public void didFailToRecordClick(String uri, CBClickError error)

//Called after the SDK has been successfully initialized and video prefetching has been completed.
public void didInitialize()
{ Log.i("Chartboost, DID INITIALIZE! ")); }
Don’t make cache or show calls inside didFailToLoad delegates or the universe will implode.
 
▲ Back to top

Age gate methods for Android have been deprecated.
 
▲ Back to top
  public void onCreate() {
      super.onCreate();
      // Get the consent status via the Chartboost.getPIDataUseConsent().getValue() method. 
      Chartboost.getPIDataUseConsent().getValue()

      // Set the consent status corresponding to the user's response using 
      // the Chartboost.setPIDataUseConsent(this, Chartboost.CBPIDataUseConsent.YES_BEHAVIORAL) method.
      Chartboost.setPIDataUseConsent(this, Chartboost.CBPIDataUseConsent.YES_BEHAVIORAL)

      Chartboost.startWithAppId(this, appId, appSignature);
   }   
 

@Override
public void onBackPressed() {
    // If an interstitial is on screen, close it.
    if (Chartboost.onBackPressed())
        return;
    else
        super.onBackPressed();
}
 

Last Updated on December 1, 2020