Legacy (Pre-3.3) Android Unity Integrations

Last Update:

Contents


Basic Integration

Fire up Unity and import the plugin files: Right-click Assets in the Project section, then mouse over Import Package and click Custom Package:

The C# files exposing the Chartboost SDK methods — ChartBoostAndroid.cs and ChartBoostAndroidManager.cs — are located in the Chartboost directory (Assets > Plugins > ChartboostAndroid). The native SDK and java wrapper files are located in the Android directory (Assets > Plugins > Android).

If you navigate to the new Demo directory (Assets > Plugins > ChartboostAndroid > Demo), you'll see two C# scripts — ChartBoostGUIManager and ChartBoostEventListener. These scripts demonstrate how to hook up exposed methods from ChartBoostAndroid.cs (for a basic integration) and ChartBoostAndroidManager.cs (to use delegate methods) in any of your scripts:

ChartBoostAndroid.cs and ChartBoostAndroidManager.cs list all available Chartboost methods, which are also available for reference below.

Important note: Before the Android plugin will function, you'll need to add the CBDialogActivity activity and android.permission.INTERNET permission to your AndroidManifest file — just copy-paste the activity declaration and permissions from the manifest file in Assets > Plugins > ChartBoostAndroid.

On application launch, be sure to call init with your App ID and AppSignature to prepare Chartboost, and onStart to let Chartboost know you're ready to go. After that, you're clear to show interstitials.

ChartBoostAndroid.cs exposes the following methods:

// Android Activity Lifecycle Methods
public static void onStart()

public static void onDestroy()

public static void onStop()

public static void onBackPressed()

// Starts up Chartboost and records an install or bootup
public static void init( string appId, string appSignature, bool shouldRequestInterstitialsInFirstSession = true )

// Caches an interstitial. Location is optional; pass in "null" if you don't want to specify one.
public static void cacheInterstitial( string location )

// Checks for a cached interstitial. Location is optional; pass in "null" if you don't want to specify one.
public static bool hasCachedInterstitial( string location )

// Loads an interstitial. Location is optional; pass in "null" if you don't want to specify the location.
public static void showInterstitial( string location )

Best Practices
  • Init and onStart only need to be called once per session; they should not be called again when switching scenes
  • A "session" includes both hard bootups and soft bootups — Init and onStart should be included in methods that will fire when the game first boots and each time it becomes active from the background

Advanced Integration

ChartBoostAndroidManager.cs fires the following events:

// Fired when an interstitial fails to load
public static event Action didFailToLoadInterstitialEvent;

// Fired when an interstitial is shown
public static event Action didShowInterstitialEvent;


Don't make cache or show calls inside didFailToLoad delegates or the universe will implode.