在 Android 中初始化 SDK
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 分钟最后更新 2 days ago
要初始化该 SDK,必须为适当平台引用项目的 Game ID(游戏 ID)。在 Monetization(变现)后台的二级导航菜单中选择 CURRENT PROJECT(当前项目)> Project Settings(项目设置),即可找到该 ID。 在游戏脚本中,需要实现一个
IUnityAdsInitializationListener
对于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) { } }
initialize
context
Context
unityGameID
IUnityAdsInitializationListener
true
后续步骤:请参阅关于在 Android 中实现基本广告的文档以继续您的集成。