文档

Development

User Acquisition

Monetization

工业

Unity Ads Monetization

SDK 4.20.0

受支持
​

Android API reference

Unity Ads Monetization

SDK 4.20.0

受支持
​

此页面不支持所选语言。
Android developer guides
​
​
Android developer guides
  • Android SDK integration guide
  • Unity Ads privacy guide
  • Unity Ads SDK troubleshooting guide
  • Android developer API references
  1. Unity Ads SDK Android developer monetization
  2. Unity Ads SDK integration guide for Android developers

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.
阅读时间1 分钟
最后更新于 1 个月前

重要
You must configure user consent before or during SDK initialization. Serving ads without consent configuration may violate privacy regulations in some regions.
To initialize the SDK, you need your app's Game ID for the target platform. To locate it, go to the Unity Monetization Dashboard, then navigate to Monetization > Apps > [your app] > Network.
Initialize the SDK early in your project's run-time life cycle before you need to load an ad. Refer to the following code sample to understand how to initialize the Unity Ads SDK.

SDK initialization example

Use
InitializationConfiguration.Builder
to construct a configuration object with your Game ID, test mode flag, and mediation metadata, then pass it to
UnityAds.initialize()
along with an
InitializationListener
. The listener's
onInitializationComplete
callback receives a
UnityAdsError
if initialization fails, or
null
on success.
InitializationConfiguration config = new InitializationConfiguration.Builder("YOUR_GAME_ID") .withTestMode(true) .build();InitializationListener listener = error -> { if (error == null) { // Initialization successful } else { // Handle initialization error }};UnityAds.initialize(config, listener);
val config = InitializationConfiguration.Builder("YOUR_GAME_ID") .withTestMode(true) .build()val listener = InitializationListener { error -> if (error == null) { // Initialization successful } else { // Handle initialization error }}UnityAds.initialize(config, listener)
Next steps: To continue your integration, refer to the Implement interstitial ads in Android documentation.

Copyright © 2026 Unity Technologies
法律信息隐私政策CookiesDocumentation Terms of Use请勿出售或分享我的个人信息您的隐私选择(Cookie 设置)

“Unity”、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属公司在美国和其他地方的商标或注册商标(此处查看更多信息)。其他名称或品牌是其各自所有者的商标。

为方便起见,一些页面是机器翻译的,可能包含不准确的内容。如有信息不一致的情况,以英文版本为准。

  • 在本页上
    • SDK initialization example


报告此页面的问题
​
​