google-mobile-ads-android-migrate-to-next-gen

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

AI Migration Agent Instructions for the Google Mobile Ads SDK

Google Mobile Ads SDK的AI迁移Agent指南

Migration Workflow

迁移工作流

Use this checklist to track your migration progress:
  • Configure Gradle:
    • Replace
      com.google.android.gms:play-services-ads
      with the latest stable version of
      com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk
      . If you cannot access Maven directly, run the following command to fetch the latest version. The version returned in the
      latest
      tag is the latest version of the GMA Next-Gen SDK:
      bash
      curl -sS https://dl.google.com/dl/android/maven2/com/google/android/libraries/ads/mobile/sdk/ads-mobile-sdk/maven-metadata.xml | sed -n 's/.*<latest>\(.*\)<\/latest>.*/\1/p'
    • Update
      minSdk
      (24+) and
      compileSdk
      (34+).
    • Exclude
      play-services-ads
      and
      play-services-ads-lite
      from all dependencies globally in the app-level build file to avoid duplicate symbol errors.
    • Sync Gradle before moving on to the next step.
  • Per-File Migration:
    • Refactor the codebase following the API Mapping and Method Mapping tables to migrate imports, class names, and method signature to GMA Next-Gen SDK.
  • Verify and Build:
    • Run
      gradle build -x test
      to confirm a successful clean build. Resolve any GMA SDK related compile errors.
使用此清单跟踪迁移进度:
  • 配置Gradle:
    • com.google.android.gms:play-services-ads
      替换为
      com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk
      的最新稳定版本。如果无法直接访问Maven,运行以下命令获取最新版本。
      latest
      标签中返回的版本即为GMA Next-Gen SDK的最新版本:
      bash
      curl -sS https://dl.google.com/dl/android/maven2/com/google/android/libraries/ads/mobile/sdk/ads-mobile-sdk/maven-metadata.xml | sed -n 's/.*<latest>\(.*\)<\/latest>.*/\1/p'
    • 更新
      minSdk
      (24+)和
      compileSdk
      (34+)。
    • 在应用级构建文件中全局排除所有依赖项中的
      play-services-ads
      play-services-ads-lite
      ,以避免重复符号错误。
    • 同步Gradle后再进行下一步。
  • 逐文件迁移:
    • 遵循API映射和方法映射表重构代码库,将导入项、类名和方法签名迁移至GMA Next-Gen SDK。
  • 验证与构建:
    • 运行
      gradle build -x test
      确认构建成功。解决所有与GMA SDK相关的编译错误。

Core Migration Rules

核心迁移规则

  • App ID Usage: Always use the value of the
    com.google.android.gms.ads.APPLICATION_ID
    meta-data tag from
    AndroidManifest.xml
    for the
    applicationId
    in
    InitializationConfig
    .
    • Constraint: Preserve the
      <meta-data>
      tag in the manifest; it is still required for publishers using the User Messaging Platform SDK.
  • Initialization Sequence:
    1. Call
      MobileAds.initialize()
      on a background thread.
    2. Ensure
      initialize()
      is called before any other SDK methods.
    3. If using
      RequestConfiguration
      , bundle it into
      InitializationConfig.Builder.setRequestConfiguration()
      . Do not call
      MobileAds.setRequestConfiguration()
      before initialization.
  • UI Threading: MANDATORY: Callbacks in GMA-Next Gen SDK are invoked on a background thread. ALL UI-RELATED OPERATIONS (e.g., Toasts, View updates, Fragment transactions) MUST be wrapped in
    runOnUiThread {}
    or
    Dispatchers.Main.launch {}
    within GMA SDK callbacks. SKIPPING THIS STEP WILL CAUSE THE APPLICATION TO CRASH.
  • Mediation: Classes implementing
    com.google.android.gms.ads.mediation.Adapter
    MUST continue using
    com.google.android.gms.ads
    .
  • App ID使用: 务必使用
    AndroidManifest.xml
    com.google.android.gms.ads.APPLICATION_ID
    元数据标签的值作为
    InitializationConfig
    中的
    applicationId
    • 约束: 保留清单中的
      <meta-data>
      标签;对于使用User Messaging Platform SDK的发布商,该标签仍然是必需的。
  • 初始化顺序:
    1. 在后台线程调用
      MobileAds.initialize()
    2. 确保
      initialize()
      在所有其他SDK方法之前调用。
    3. 如果使用
      RequestConfiguration
      ,将其打包到
      InitializationConfig.Builder.setRequestConfiguration()
      中。不要在初始化前调用
      MobileAds.setRequestConfiguration()
  • UI线程处理: 强制要求:GMA Next-Gen SDK中的回调会在后台线程触发。所有UI相关操作(如Toasts、视图更新、Fragment事务)必须在GMA SDK回调中用
    runOnUiThread {}
    Dispatchers.Main.launch {}
    包裹。跳过此步骤会导致应用崩溃。
  • 中介: 实现
    com.google.android.gms.ads.mediation.Adapter
    的类必须继续使用
    com.google.android.gms.ads

Format Specifics

格式细节

Banner Ads

Banner广告

  • Use
    com.google.android.libraries.ads.mobile.sdk.banner.AdView
    for loading GMA Next-Gen SDK banners.
  • The following API checks if a banner is collapsible:
    adView.getBannerAd().isCollapsible()
    .
  • 使用
    com.google.android.libraries.ads.mobile.sdk.banner.AdView
    加载GMA Next-Gen SDK的Banner广告。
  • 以下API用于检查Banner是否可折叠:
    adView.getBannerAd().isCollapsible()

Native Ads

Native广告

  • NativeAdLoader:
    NativeAdLoader
    is abstract and cannot be instantiated. It is used statically (e.g.,
    NativeAdLoader.load(...)
    ).
  • The following APIs are now set on the
    NativeAdRequest.Builder
    :
    • .setCustomFormatIds(customFormatIds: List<String>)
    • .disableImageDownloading()
    • .setMediaAspectRatio(mediaAspectRatio: NativeMediaAspectRatio)
    • .setAdChoicesPlacement(adChoicesPlacement: AdChoicesPlacement)
    • .setVideoOptions(videoOptions: VideoOptions)
  • Removal: Delete all "Mute This Ad" logic; it is unsupported in GMA Next-Gen SDK.
  • MediaView:
    NativeAd
    no longer has a direct
    mediaView
    variable; use
    registerNativeAd(nativeAd, mediaView)
    to associate the ad with the view.
  • NativeAdLoader:
    NativeAdLoader
    是抽象类,无法实例化。需静态使用(例如:
    NativeAdLoader.load(...)
    )。
  • 以下API现在设置在
    NativeAdRequest.Builder
    上:
    • .setCustomFormatIds(customFormatIds: List<String>)
    • .disableImageDownloading()
    • .setMediaAspectRatio(mediaAspectRatio: NativeMediaAspectRatio)
    • .setAdChoicesPlacement(adChoicesPlacement: AdChoicesPlacement)
    • .setVideoOptions(videoOptions: VideoOptions)
  • 移除: 删除所有"静音此广告"逻辑;GMA Next-Gen SDK不支持该功能。
  • MediaView:
    NativeAd
    不再有直接的
    mediaView
    变量;使用
    registerNativeAd(nativeAd, mediaView)
    将广告与视图关联。

Ad preloading

广告预加载

  • Unless specified in the mapping table, ad preloading methods in the GMA Next-Gen SDK retain the same API signatures and parameters as the Old SDK.
  • 除非映射表中另有说明,GMA Next-Gen SDK中的广告预加载方法保留与旧版SDK相同的API签名和参数。

API Mapping

API映射

This table covers the main classes and their GMA Next-Gen SDK equivalents.
FeatureOld SDK Import (
com.google.android.gms.ads...
)
GMA Next-Gen SDK Import (
com.google.android.libraries.ads.mobile.sdk...
)
Core
Initialization
MobileAds
MobileAds
,
initialization.InitializationConfig
Initialization Listener
initialization.OnInitializationCompleteListener
initialization.OnAdapterInitializationCompleteListener
Ad Request
AdRequest
Format specific (e.g.
common.AdRequest
,
banner.BannerAdRequest
,
nativead.NativeAdRequest
) (Ad Unit ID is declared in
Builder
. Load() no longer takes an activity)
Load Error
LoadAdError
common.LoadAdError
(
LoadAdError
no longer has a domain variable. REMOVE the domain variable if found.)
Full Screen Show Error
AdError
(within
FullScreenContentCallback
)
common.FullScreenContentError
(within format-specific
AdEventCallback
)
Request Configuration
RequestConfiguration
common.RequestConfiguration
(Nested Enums/Constants for RequestConfiguration are now under common.RequestConfiguration.)
Event Callbacks
FullScreenContentCallback
(for full screen formats),
AdListener
(Banner, Native)
Format Specific (e.g.,
interstitial.InterstitialAdEventCallback
,
banner.BannerAdEventCallback
,
native.NativeAdEventCallback
). Variable on the ad format is
adEventCallback
.
Tools
Ad Inspector
MobileAds.openAdInspector()
MobileAds.openAdInspector()
(
openAdInspector
no longer takes an activity)
Ad Inspector Listener
OnAdInspectorClosedListener
common.OnAdInspectorClosedListener
Formats
App Open
appopen.AppOpenAd
appopen.AppOpenAd
App Open Load
appopen.AppOpenAd.AppOpenAdLoadCallback
common.AdLoadCallback<appopen.AppOpenAd>
Banner
AdView
,
AdSize
banner.AdView
,
banner.AdSize
(
AdView
no longer has
pause()
,
resume()
,
setAdSize()
).
AdSize
is declared in
BannerAdRequest
.
Banner Load
AdListener
common.AdLoadCallback<banner.BannerAd>
Banner Events
AdListener
banner.BannerAdEventCallback
,
banner.BannerAdRefreshCallback
Interstitial
interstitial.InterstitialAd
interstitial.InterstitialAd
Interstitial Load
interstitial.InterstitialAd.InterstitialAdLoadCallback
common.AdLoadCallback<interstitial.InterstitialAd>
Ad Loader
AdLoader
nativead.NativeAdLoader
Native
nativead.NativeAd
nativead.NativeAd
(No longer has a
mediaView
variable)
Native Custom Format Ad
nativead.NativeCustomFormatAd
nativead.CustomNativeAd
Native Custom Click
nativead.NativeCustomFormatAd.OnCustomClickListener
nativead.OnCustomClickListener
(set on the
CustomNativeAd
object (e.g.,
.onCustomClickListener
)
Native Load
nativead.NativeAd.OnNativeAdLoadedListener
nativead.NativeAdLoaderCallback
Native Ad View
nativead.NativeAdView
nativead.NativeAdView
Media Content
MediaContent
nativead.MediaContent
(hasVideoContent is declared as a
val
)
Media Aspect Ratio
MediaAspectRatio
nativead.MediaAspectRatio
Video Options
VideoOptions
common.VideoOptions
Video Controller
VideoController
common.VideoController
(VideoLifecycleCallbacks is now an interface, so instantiate with
object : VideoController.VideoLifecycleCallbacks { ... }
)
Rewarded
rewarded.RewardedAd
rewarded.RewardedAd
Rewarded Load
rewarded.RewardedAd.RewardedAdLoadCallback
common.AdLoadCallback<rewarded.RewardedAd>
Rewarded Interstitial
rewardedinterstitial.RewardedInterstitialAd
rewardedinterstitial.RewardedInterstitialAd
Rewarded Interstitial Load
rewardedinterstitial.RewardedInterstitialAd.RewardedInterstitialAdLoadCallback
common.AdLoadCallback<rewardedinterstitial.RewardedInterstitialAd>
Paid Event Listener
OnPaidEventListener
common.AdEventCallback
Response Info
ResponseInfo
common.ResponseInfo
Adapter Response Info
AdapterResponseInfo
common.AdSourceResponseInfo
Rewards
Reward Listener
OnUserEarnedRewardListener
rewarded.OnUserEarnedRewardListener
Reward Item
rewarded.RewardItem
rewarded.RewardItem
(property access on
RewardedAd
and
RewardedInterstitialAd
is now
getRewardItem()
)
Ad Value
AdValue
common.AdValue
Preloading
Configuration
preload.PreloadConfiguration
common.PreloadConfiguration
Callback
preload.PreloadCallbackV2
common.PreloadCallback
(Now an interface instead of an abstract class)
Interstitial Preloader
interstitial.InterstitialPreloader
interstitial.InterstitialAdPreloader
Ad Manager
Ad Request
admanager.AdManagerAdRequest
common.AdRequest
(Now directly implemented in the
AdRequest
class)
Ad View
admanager.AdView
banner.AdView
(No
AdManagerAdView
class)
App Event Listener
admanager.AppEventListener
common.OnAppEventListener
此表涵盖主要类及其对应的GMA Next-Gen SDK等效类。
功能旧版SDK导入路径 (
com.google.android.gms.ads...
)
GMA Next-Gen SDK导入路径 (
com.google.android.libraries.ads.mobile.sdk...
)
核心
初始化
MobileAds
MobileAds
,
initialization.InitializationConfig
初始化监听器
initialization.OnInitializationCompleteListener
initialization.OnAdapterInitializationCompleteListener
广告请求
AdRequest
按格式区分(例如
common.AdRequest
,
banner.BannerAdRequest
,
nativead.NativeAdRequest
)(广告单元ID在
Builder
中声明。
Load()
不再接收activity参数)
加载错误
LoadAdError
common.LoadAdError
LoadAdError
不再有domain变量。如果发现该变量请移除。)
全屏展示错误
AdError
(位于
FullScreenContentCallback
内)
common.FullScreenContentError
(位于特定格式的
AdEventCallback
内)
请求配置
RequestConfiguration
common.RequestConfiguration
(RequestConfiguration的嵌套枚举/常量现在位于common.RequestConfiguration下。)
事件回调
FullScreenContentCallback
(针对全屏格式),
AdListener
(Banner、Native)
按格式区分(例如
interstitial.InterstitialAdEventCallback
,
banner.BannerAdEventCallback
,
native.NativeAdEventCallback
)。广告格式上的变量名为
adEventCallback
工具
广告检查器
MobileAds.openAdInspector()
MobileAds.openAdInspector()
openAdInspector
不再接收activity参数)
广告检查器监听器
OnAdInspectorClosedListener
common.OnAdInspectorClosedListener
广告格式
开屏广告
appopen.AppOpenAd
appopen.AppOpenAd
开屏广告加载
appopen.AppOpenAd.AppOpenAdLoadCallback
common.AdLoadCallback<appopen.AppOpenAd>
Banner广告
AdView
,
AdSize
banner.AdView
,
banner.AdSize
AdView
不再有
pause()
,
resume()
,
setAdSize()
方法。
AdSize
BannerAdRequest
中声明。)
Banner广告加载
AdListener
common.AdLoadCallback<banner.BannerAd>
Banner广告事件
AdListener
banner.BannerAdEventCallback
,
banner.BannerAdRefreshCallback
插屏广告
interstitial.InterstitialAd
interstitial.InterstitialAd
插屏广告加载
interstitial.InterstitialAd.InterstitialAdLoadCallback
common.AdLoadCallback<interstitial.InterstitialAd>
广告加载器
AdLoader
nativead.NativeAdLoader
Native广告
nativead.NativeAd
nativead.NativeAd
(不再有
mediaView
变量)
Native自定义格式广告
nativead.NativeCustomFormatAd
nativead.CustomNativeAd
Native自定义点击
nativead.NativeCustomFormatAd.OnCustomClickListener
nativead.OnCustomClickListener
(设置在
CustomNativeAd
对象上,例如
.onCustomClickListener
Native广告加载
nativead.NativeAd.OnNativeAdLoadedListener
nativead.NativeAdLoaderCallback
Native广告视图
nativead.NativeAdView
nativead.NativeAdView
媒体内容
MediaContent
nativead.MediaContent
(hasVideoContent声明为
val
媒体宽高比
MediaAspectRatio
nativead.MediaAspectRatio
视频选项
VideoOptions
common.VideoOptions
视频控制器
VideoController
common.VideoController
(VideoLifecycleCallbacks现在是接口,需通过
object : VideoController.VideoLifecycleCallbacks { ... }
实例化)
激励广告
rewarded.RewardedAd
rewarded.RewardedAd
激励广告加载
rewarded.RewardedAd.RewardedAdLoadCallback
common.AdLoadCallback<rewarded.RewardedAd>
激励插屏广告
rewardedinterstitial.RewardedInterstitialAd
rewardedinterstitial.RewardedInterstitialAd
激励插屏广告加载
rewardedinterstitial.RewardedInterstitialAd.RewardedInterstitialAdLoadCallback
common.AdLoadCallback<rewardedinterstitial.RewardedInterstitialAd>
付费事件监听器
OnPaidEventListener
common.AdEventCallback
响应信息
ResponseInfo
common.ResponseInfo
适配器响应信息
AdapterResponseInfo
common.AdSourceResponseInfo
奖励
奖励监听器
OnUserEarnedRewardListener
rewarded.OnUserEarnedRewardListener
奖励项
rewarded.RewardItem
rewarded.RewardItem
(在
RewardedAd
RewardedInterstitialAd
上的属性访问现在为
getRewardItem()
广告价值
AdValue
common.AdValue
预加载
配置
preload.PreloadConfiguration
common.PreloadConfiguration
回调
preload.PreloadCallbackV2
common.PreloadCallback
(现在是接口而非抽象类)
插屏广告预加载器
interstitial.InterstitialPreloader
interstitial.InterstitialAdPreloader
Ad Manager
广告请求
admanager.AdManagerAdRequest
common.AdRequest
(现在直接在
AdRequest
类中实现)
广告视图
admanager.AdView
banner.AdView
(不再有
AdManagerAdView
类)
应用事件监听器
admanager.AppEventListener
common.OnAppEventListener

Method Mapping

方法映射

This table covers the main methods and their GMA Next-Gen SDK equivalents.
FeatureOld SDK Method SignatureGMA Next-Gen SDK Method Signature
Core
MobileAds Initialization
MobileAds.initialize(Context context, OnInitializationCompleteListener listener)
MobileAds.initialize(Context context, InitializationConfig config, OnInitializationCompleteListener listener)
InitializationConfig BuilderN/A
InitializationConfig.Builder(String applicationId)
Ad Request Builder
AdRequest.Builder().build()
AdRequest.Builder(String adUnitId).build()
(for App Open, Interstitial, Rewarded, Rewarded Interstitial) Banner:
BannerAdRequest.Builder(String adUnitId, AdSize adSize).build()
Native:
NativeAdRequest.Builder(String adUnitId, nativeAdTypes: List<NativeAdType>).build()
Add Network Extras (AdMobAdapter)
AdRequest.Builder().addNetworkExtrasBundle(Class<MediationExtrasReceiver>, Bundle networkExtras)
AdRequest.Builder(String adUnitId).setGoogleExtrasBundle(Bundle extraBundle)
Add Network Extras (Ad Source Adapter)
AdRequest.Builder().addNetworkExtrasBundle(Class<MediationExtrasReceiver>, Bundle networkExtras)
AdRequest.Builder(String adUnitId).putAdSourceExtrasBundle(Class<MediationExtrasReceiver> adapterClass, Bundle adSourceExtras)
Custom Targeting
AdRequest.Builder().setCustomTargeting(String key, String value)
AdRequest.Builder(String adUnitId).putCustomTargeting(String key, String value)
Formats
App Open
AppOpenAd.load(Context context, String adUnitId, AdRequest request, AppOpenAdLoadCallback loadCallback)
AppOpenAd.load(AdRequest request, AdLoadCallback<AppOpenAd> loadCallback)
Banner
AdView.loadAd(AdRequest request)
AdView.loadAd(BannerAdRequest request, AdLoadCallback<BannerAd> loadCallback)
Interstitial
InterstitialAd.load(Context context, String adUnitId, AdRequest request, InterstitialAdLoadCallback loadCallback)
InterstitialAd.load(AdRequest request, AdLoadCallback<InterstitialAd> loadCallback)
Rewarded
RewardedAd.load(Context context, String adUnitId, AdRequest request, RewardedAdLoadCallback loadCallback)
RewardedAd.load(AdRequest request, AdLoadCallback<RewardedAd> loadCallback)
Rewarded Interstitial
RewardedInterstitialAd.load(Context context, String adUnitId, AdRequest request, RewardedInterstitialAdLoadCallback loadCallback)
RewardedInterstitialAd.load(AdRequest request, AdLoadCallback<RewardedInterstitialAd> loadCallback)
Native Builder
AdLoader.Builder(Context context, String adUnitId).forNativeAd(NativeAd.OnNativeAdLoadedListener onNativeAdLoadedListener)
NativeAdRequest.Builder(String adUnitId, nativeAdTypes: List<NativeAdType>)
(Include
NativeAd.NativeAdType.NATIVE
in
nativeAdTypes
)
Native Load
AdLoader.Builder(...).build().loadAd(AdRequest request)
NativeAdLoader.load(NativeAdRequest request, NativeAdLoaderCallback callback)
Native Ad Register
NativeAdView.setNativeAd(NativeAd nativeAd)
NativeAdView.registerNativeAd(NativeAd nativeAd, mediaView: MediaView?)
Set an App Event Listener (Banner)
AdManagerAdView.appEventListener
BannerAd.adEventCallback
(
onAppEvent(name: String, data: String?)
is now part of the
BannerAdEventCallback
)
Set an App Event Listener (Interstitial)
AdManagerInterstitialAd.appEventListener
InterstitialAd.adEventCallback
(
onAppEvent(name: String, data: String?)
is now part of the
InterstitialAdEventCallback
)
Callbacks
onAdOpened
AdListener.onAdOpened()
AdEventCallback.onAdShowedFullScreenContent()
onAdClosed
AdListener.onAdClosed()
AdEventCallback.onAdDismissedFullScreenContent()
onFailedToShowFullScreenContent
onAdFailedToShowFullScreenContent(adError: AdError)
onAdFailedToShowFullScreenContent(fullScreenContentError: FullScreenContentError)
onAdLoadedAdLoadCallback:
onAdLoaded(ad: T)
(e.g.,
InterstitialAdLoadCallback
,
RewardedAdLoadCallback
,
RewardedInterstitialAdLoadCallback
)
Parameter name is always
ad
Format specific:
onAdLoaded(ad: InterstitialAd)
,
onAdLoaded(ad: RewardedAd)
,
onAdLoaded(ad: RewardedInterstitialAd)
onAdFailedToLoad
onAdFailedToLoad(loadAdError: LoadAdError)
onAdFailedToLoad(adError: LoadAdError)
onCustomFormatAdLoaded
OnCustomFormatAdLoadedListener.onCustomFormatAdLoaded(NativeCustomFormatAd ad)
NativeAdLoaderCallback.onCustomNativeAdLoaded(CustomNativeAd customNativeAd)
onPaidEventListener
OnPaidEventListener.onPaidEvent(AdValue value)
AdEventCallback.onAdPaid(value: AdValue)
(Format-specific e.g.,
banner.BannerAdEventCallback.onAdPaid(value: AdValue)
)
onVideoMute
onVideoMute(muted: Boolean)
onVideoMute(isMuted: Boolean)
onAdPreloaded
onAdPreloaded(preloadId: String, responseInfo: ResponseInfo?)
onAdPreloaded(preloadId: String, responseInfo: ResponseInfo)
Preloading
Configuration
PreloadConfiguration.Builder(String adUnitId).build()
PreloadConfiguration(AdRequest request)
Response Info
Get Response Info
ad.responseInfo
ad.getResponseInfo()
Loaded Adapter Responses Info
responseInfo.getLoadedAdapterResponseInfo()
responseInfo.loadedAdSourceResponseInfo
Get Adapter Responses
responseInfo.getAdapterResponses()
responseInfo.adSourceResponses
Get Mediation Adapter Class
responseInfo.getMediationAdapterClassName()
responseInfo.adapterClassName
Adapter Response Info
Ad Source ID
AdapterResponseInfo.getAdSourceId()
AdSourceResponseInfo.id
Ad Source Name
AdapterResponseInfo.getAdSourceName()
AdSourceResponseInfo.name
Ad Source Instance ID
AdapterResponseInfo.getAdSourceInstanceId()
AdSourceResponseInfo.instanceId
Ad Source Instance Name
AdapterResponseInfo.getAdSourceInstanceName()
AdSourceResponseInfo.instanceName
此表涵盖主要方法及其对应的GMA Next-Gen SDK等效方法。
功能旧版SDK方法签名GMA Next-Gen SDK方法签名
核心
MobileAds初始化
MobileAds.initialize(Context context, OnInitializationCompleteListener listener)
MobileAds.initialize(Context context, InitializationConfig config, OnInitializationCompleteListener listener)
InitializationConfig构建器N/A
InitializationConfig.Builder(String applicationId)
广告请求构建器
AdRequest.Builder().build()
AdRequest.Builder(String adUnitId).build()
(适用于开屏、插屏、激励、激励插屏广告) Banner广告:
BannerAdRequest.Builder(String adUnitId, AdSize adSize).build()
Native广告:
NativeAdRequest.Builder(String adUnitId, nativeAdTypes: List<NativeAdType>).build()
添加网络额外信息(AdMobAdapter)
AdRequest.Builder().addNetworkExtrasBundle(Class<MediationExtrasReceiver>, Bundle networkExtras)
AdRequest.Builder(String adUnitId).setGoogleExtrasBundle(Bundle extraBundle)
添加网络额外信息(广告源适配器)
AdRequest.Builder().addNetworkExtrasBundle(Class<MediationExtrasReceiver>, Bundle networkExtras)
AdRequest.Builder(String adUnitId).putAdSourceExtrasBundle(Class<MediationExtrasReceiver> adapterClass, Bundle adSourceExtras)
自定义定向
AdRequest.Builder().setCustomTargeting(String key, String value)
AdRequest.Builder(String adUnitId).putCustomTargeting(String key, String value)
广告格式
开屏广告
AppOpenAd.load(Context context, String adUnitId, AdRequest request, AppOpenAdLoadCallback loadCallback)
AppOpenAd.load(AdRequest request, AdLoadCallback<AppOpenAd> loadCallback)
Banner广告
AdView.loadAd(AdRequest request)
AdView.loadAd(BannerAdRequest request, AdLoadCallback<BannerAd> loadCallback)
插屏广告
InterstitialAd.load(Context context, String adUnitId, AdRequest request, InterstitialAdLoadCallback loadCallback)
InterstitialAd.load(AdRequest request, AdLoadCallback<InterstitialAd> loadCallback)
激励广告
RewardedAd.load(Context context, String adUnitId, AdRequest request, RewardedAdLoadCallback loadCallback)
RewardedAd.load(AdRequest request, AdLoadCallback<RewardedAd> loadCallback)
激励插屏广告
RewardedInterstitialAd.load(Context context, String adUnitId, AdRequest request, RewardedInterstitialAdLoadCallback loadCallback)
RewardedInterstitialAd.load(AdRequest request, AdLoadCallback<RewardedInterstitialAd> loadCallback)
Native广告构建器
AdLoader.Builder(Context context, String adUnitId).forNativeAd(NativeAd.OnNativeAdLoadedListener onNativeAdLoadedListener)
NativeAdRequest.Builder(String adUnitId, nativeAdTypes: List<NativeAdType>)
(在
nativeAdTypes
中包含
NativeAd.NativeAdType.NATIVE
Native广告加载
AdLoader.Builder(...).build().loadAd(AdRequest request)
NativeAdLoader.load(NativeAdRequest request, NativeAdLoaderCallback callback)
Native广告注册
NativeAdView.setNativeAd(NativeAd nativeAd)
NativeAdView.registerNativeAd(NativeAd nativeAd, mediaView: MediaView?)
设置应用事件监听器(Banner广告)
AdManagerAdView.appEventListener
BannerAd.adEventCallback
onAppEvent(name: String, data: String?)
现在是
BannerAdEventCallback
的一部分)
设置应用事件监听器(插屏广告)
AdManagerInterstitialAd.appEventListener
InterstitialAd.adEventCallback
onAppEvent(name: String, data: String?)
现在是
InterstitialAdEventCallback
的一部分)
回调
onAdOpened
AdListener.onAdOpened()
AdEventCallback.onAdShowedFullScreenContent()
onAdClosed
AdListener.onAdClosed()
AdEventCallback.onAdDismissedFullScreenContent()
onFailedToShowFullScreenContent
onAdFailedToShowFullScreenContent(adError: AdError)
onAdFailedToShowFullScreenContent(fullScreenContentError: FullScreenContentError)
onAdLoadedAdLoadCallback:
onAdLoaded(ad: T)
(例如
InterstitialAdLoadCallback
,
RewardedAdLoadCallback
,
RewardedInterstitialAdLoadCallback
参数名称始终为
ad
按格式区分:
onAdLoaded(ad: InterstitialAd)
,
onAdLoaded(ad: RewardedAd)
,
onAdLoaded(ad: RewardedInterstitialAd)
onAdFailedToLoad
onAdFailedToLoad(loadAdError: LoadAdError)
onAdFailedToLoad(adError: LoadAdError)
onCustomFormatAdLoaded
OnCustomFormatAdLoadedListener.onCustomFormatAdLoaded(NativeCustomFormatAd ad)
NativeAdLoaderCallback.onCustomNativeAdLoaded(CustomNativeAd customNativeAd)
onPaidEventListener
OnPaidEventListener.onPaidEvent(AdValue value)
AdEventCallback.onAdPaid(value: AdValue)
(按格式区分,例如
banner.BannerAdEventCallback.onAdPaid(value: AdValue)
onVideoMute
onVideoMute(muted: Boolean)
onVideoMute(isMuted: Boolean)
onAdPreloaded
onAdPreloaded(preloadId: String, responseInfo: ResponseInfo?)
onAdPreloaded(preloadId: String, responseInfo: ResponseInfo)
预加载
配置
PreloadConfiguration.Builder(String adUnitId).build()
PreloadConfiguration(AdRequest request)
响应信息
获取响应信息
ad.responseInfo
ad.getResponseInfo()
已加载适配器响应信息
responseInfo.getLoadedAdapterResponseInfo()
responseInfo.loadedAdSourceResponseInfo
获取适配器响应
responseInfo.getAdapterResponses()
responseInfo.adSourceResponses
获取中介适配器类
responseInfo.getMediationAdapterClassName()
responseInfo.adapterClassName
适配器响应信息
广告源ID
AdapterResponseInfo.getAdSourceId()
AdSourceResponseInfo.id
广告源名称
AdapterResponseInfo.getAdSourceName()
AdSourceResponseInfo.name
广告源实例ID
AdapterResponseInfo.getAdSourceInstanceId()
AdSourceResponseInfo.instanceId
广告源实例名称
AdapterResponseInfo.getAdSourceInstanceName()
AdSourceResponseInfo.instanceName