Initialize the SDK in Android
Initialize the Unity Ads SDK in your Android app. Set your Game ID and configure a listener to handle initialization status and enable ad monetization.
Read time 1 minuteLast updated 3 months ago
To initialize the SDK, you must reference your Project's Game ID for the appropriate platform. You can locate the ID on the Unity Monetization Dashboard by selecting CURRENT PROJECT > Project Settings from the secondary navigation menu.
In your game script, you need to implement an interface that handles initialization callbacks. The initialize method to initialize the SDK requires this listener as a parameter. Initialize the SDK early in your project's run-time life cycle before you need to load an ad. For example:
IUnityAdsInitializationListenerSDK initialization example
import android.os.Bundle;import androidx.appcompat.app.AppCompatActivity;import com.unity3d.ads.example.R;import com.unity3d.ads.IUnityAdsInitializationListener;import com.unity3d.ads.UnityAds;public class InitializeAdsScript extends AppCompatActivity implements IUnityAdsInitializationListener { private String unityGameID = "1234567"; private Boolean testMode = true; @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); // Initialize the SDK: UnityAds.initialize(getApplicationContext(), unityGameID, testMode, this); } @Override public void onInitializationComplete() { } @Override public void onInitializationFailed(UnityAds.UnityAdsInitializationError error, String message) { }}
For the function, the parameter is the current Android . The parameter is the Unity Game ID for your project, found in the Monetization dashboard, specifically the Settings page of your project. The is the listener for the result of the initialization call. The Boolean indicates that the game is in test mode, and will only show test ads.
initializecontextContextunityGameIDIUnityAdsInitializationListenertrueNext steps: To continue your integration, refer to the Implement interstitial ads in Android documentation.