要接收版本更新,请订阅 AppLovin-MAX-SDK-Android GitHub 库 。
下载最新 Android SDK
向项目添加 SDK
解压缩下载的文件,然后将 aar
文件拖拽至项目中的 libs
文件夹。
如果您的项目没有 libs
文件夹,请在 app
文件夹中创建。
Gradle
将下列行添加至您的 build.gradle
文件:
implementation ' com.applovin:applovin-sdk: «x.y.z» @aar '
implementation ( "com.applovin:applovin-sdk: «x.y.z» @aar" )
添加 SDK Key
将下列行添加至您的 AndroidManifest.xml
文件,并将它放置在 application
标签中:
< meta-data android:name = " applovin.sdk.key " android:value = " «your-SDK-key» " />
您可以在 AppLovin 控制面板的 Account > General > Keys 部分找到 SDK Key。
启用 Ad Review
要启用 MAX Ad Review 服务,请将下列行添加至您的 build.gradle
文件:
针对根层级 build.gradle
文件的补充行
maven { url ' https://artifacts.applovin.com/android ' }
classpath " com.applovin.quality:AppLovinQualityServiceGradlePlugin:+ "
maven { url = uri ( "https://artifacts.applovin.com/android" ) }
classpath ( "com.applovin.quality:AppLovinQualityServiceGradlePlugin:+" )
针对应用层级 build.gradle
文件的补充行
apply plugin : ' applovin-quality-service '
apiKey " «your-ad-review-key» "
id ( "applovin-quality-service" )
apiKey = " «your-ad-review-key» "
您可以在 AppLovin 控制面板的 Account > General > Keys 部分找到 Ad Review Key。
初始化 SDK
调用 initializeSdk()
方法,初始化 SDK,向该方法传递一个 context
请在应用启动后尽快执行此操作,例如在启动 Activity
的 onCreate()
方法中。
public class MainActivity extends Activity
protected void onCreate ( Bundle savedInstanceState )
// Set the mediation provider value to "max" to ensure proper functionality.
AppLovinSdk . getInstance ( this ) . setMediationProvider ( " max " ) ;
AppLovinSdk . initializeSdk ( this , new AppLovinSdk. SdkInitializationListener () {
public void onSdkInitialized ( final AppLovinSdkConfiguration configuration )
// AppLovin SDK is initialized, start loading ads
class MainActivity : Activity()
override fun onCreate (savedInstanceState: Bundle?)
// Set the mediation provider value to "max" to ensure proper functionality.
AppLovinSdk. getInstance ( this ). setMediationProvider ( "max" )
AppLovinSdk. getInstance ( this ). initializeSdk ({ configuration: AppLovinSdkConfiguration ->
// AppLovin SDK is initialized, start loading ads
插屏广告
加载插屏广告
要加载插屏广告,请使用您的广告单元创建一个 MaxInterstitialAd
对象,并调用 loadAd()
。实现 MaxAdListener
,以便在广告准备就绪以及发生其他广告相关事件时收到通知。
public class ExampleActivity extends Activity
private MaxInterstitialAd interstitialAd ;
private int retryAttempt ;
void createInterstitialAd ()
interstitialAd = new MaxInterstitialAd ( " «ad-unit-ID» " , this ) ;
interstitialAd . setListener ( this ) ;
public void onAdLoaded ( final MaxAd maxAd )
// Interstitial ad is ready to be shown. interstitialAd.isReady() will now return 'true'
public void onAdLoadFailed ( final String adUnitId , final MaxError error )
// Interstitial ad failed to load
// AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
long delayMillis = TimeUnit . SECONDS . toMillis ( ( long ) Math . pow ( 2 , Math . min ( 6 , retryAttempt ) ) ) ;
new Handler () . postDelayed ( new Runnable ()
public void onAdDisplayFailed ( final MaxAd maxAd , final MaxError error )
// Interstitial ad failed to display. AppLovin recommends that you load the next ad
public void onAdDisplayed ( final MaxAd maxAd ) {}
public void onAdClicked ( final MaxAd maxAd ) {}
public void onAdHidden ( final MaxAd maxAd )
// Interstitial ad is hidden. Pre-load the next ad
class ExampleActivity : Activity(), MaxAdListener
private lateinit var interstitialAd: MaxInterstitialAd
private var retryAttempt = 0.0
fun createInterstitialAd ()
interstitialAd = MaxInterstitialAd ( " «ad-unit-ID» " , this )
interstitialAd. setListener ( this )
override fun onAdLoaded (maxAd: MaxAd)
// Interstitial ad is ready to be shown. interstitialAd.isReady() will now return 'true'
override fun onAdLoadFailed (adUnitId: String?, error: MaxError?)
// Interstitial ad failed to load
// AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
val delayMillis = TimeUnit.SECONDS. toMillis ( Math. pow ( 2.0 , Math. min ( 6.0 , retryAttempt ) ). toLong () )
Handler (). postDelayed ( { interstitialAd. loadAd () }, delayMillis )
override fun onAdDisplayFailed (ad: MaxAd?, error: MaxError?)
// Interstitial ad failed to display. AppLovin recommends that you load the next ad
override fun onAdDisplayed (maxAd: MaxAd) {}
override fun onAdClicked (maxAd: MaxAd) {}
override fun onAdHidden (maxAd: MaxAd)
// Interstitial ad is hidden. Pre-load the next ad
显示插屏广告
要展示插屏广告,请在刚才创建的 MaxInterstitialAd
实例对象上调用 showAd()
if ( interstitialAd . isReady () )
if ( interstitialAd.isReady )
激励广告
加载激励广告
要加载激励广告,请使用您的激励广告单元调取一个 MaxRewardedAd
对象,并对其调用 loadAd()
。
安装 MaxRewardedAdListener
,以便在广告准备就绪以及发生其他广告相关事件时收到通知。
public class ExampleActivity extends Activity
implements MaxRewardedAdListener
private MaxRewardedAd rewardedAd ;
private int retryAttempt ;
rewardedAd = MaxRewardedAd . getInstance ( " «ad-unit-ID» " , this ) ;
rewardedAd . setListener ( this ) ;
public void onAdLoaded ( final MaxAd maxAd )
// Rewarded ad is ready to be shown. rewardedAd.isReady() will now return 'true'
public void onAdLoadFailed ( final String adUnitId , final int errorCode )
// Rewarded ad failed to load
// AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
long delayMillis = TimeUnit . SECONDS . toMillis ( ( long ) Math . pow ( 2 , Math . min ( 6 , retryAttempt ) ) ) ;
new Handler () . postDelayed ( new Runnable ()
public void onAdDisplayFailed ( final MaxAd maxAd , final MaxError error )
// Rewarded ad failed to display. AppLovin recommends that you load the next ad
public void onAdDisplayed ( final MaxAd maxAd ) {}
public void onAdClicked ( final MaxAd maxAd ) {}
public void onAdHidden ( final MaxAd maxAd )
// rewarded ad is hidden. Pre-load the next ad
public void onUserRewarded ( final MaxAd maxAd , final MaxReward maxReward )
// Rewarded ad was displayed and user should receive the reward
class ExampleActivity : Activity(), MaxRewardedAdListener
private lateinit var rewardedAd: MaxRewardedAd
private var retryAttempt = 0.0
rewardedAd = MaxRewardedAd. getInstance ( " «ad-unit-ID» " , this )
rewardedAd. setListener ( this )
override fun onAdLoaded (maxAd: MaxAd)
// Rewarded ad is ready to be shown. rewardedAd.isReady() will now return 'true'
override fun onAdLoadFailed (adUnitId: String?, error: MaxError?)
// Rewarded ad failed to load
// AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
val delayMillis = TimeUnit.SECONDS. toMillis ( Math. pow ( 2.0 , Math. min ( 6.0 , retryAttempt ) ). toLong () )
Handler (). postDelayed ( { rewardedAd. loadAd () }, delayMillis )
override fun onAdDisplayFailed (ad: MaxAd?, error: MaxError?)
// Rewarded ad failed to display. AppLovin recommends that you load the next ad
override fun onAdDisplayed (maxAd: MaxAd) {}
override fun onAdClicked (maxAd: MaxAd) {}
override fun onAdHidden (maxAd: MaxAd)
// rewarded ad is hidden. Pre-load the next ad
override fun onUserRewarded (maxAd: MaxAd, maxReward: MaxReward)
// Rewarded ad was displayed and user should receive the reward
显示激励广告
要展示激励广告,请在刚才创建的 MaxRewardedAd
实例对象上调用 showAd()
if ( rewardedAd . isReady () )
if ( rewardedAd. isReady () )
横幅和 MREC
通过程式化方法加载和展示横幅和 MREC
要加载横幅广告或 MREC,请使用您的广告单元创建一个 MaxAdView
对象,并调用 loadAd()
。要展示广告,请将 MaxAdView
对象添加为视图层级的子视图。实现 MaxAdViewAdListener
,以便在广告准备就绪以及发生其他广告相关事件时收到通知。
public class ExampleActivity extends Activity
implements MaxAdViewAdListener
private MaxAdView adView ;
adView = new MaxAdView ( " «ad-unit-ID» " , this ) ;
adView . setListener ( this ) ;
// Stretch to the width of the screen for banners to be fully functional
int width = ViewGroup . LayoutParams . MATCH_PARENT ;
// Banner height on phones and tablets is 50 and 90, respectively
int heightPx = getResources () . getDimensionPixelSize ( R . dimen . banner_height ) ;
adView . setLayoutParams ( new FrameLayout. LayoutParams ( width, heightPx ) ) ;
// Set background or background color for banners to be fully functional
adView . setBackgroundColor ( ... ) ;
ViewGroup rootView = findViewById ( android . R . id . content ) ;
rootView . addView ( adView ) ;
public void onAdLoaded ( final MaxAd maxAd ) {}
public void onAdLoadFailed ( final String adUnitId , final int errorCode ) {}
public void onAdDisplayFailed ( final MaxAd maxAd , final MaxError error ) {}
public void onAdClicked ( final MaxAd maxAd ) {}
public void onAdExpanded ( final MaxAd maxAd ) {}
public void onAdCollapsed ( final MaxAd maxAd ) {}
public void onAdDisplayed ( final MaxAd maxAd ) { /* use this for impression tracking */ }
public void onAdHidden ( final MaxAd maxAd ) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
class ExampleActivity : Activity(), MaxAdViewAdListener
private var adView: MaxAdView? = null
adView = MaxAdView ( " «ad-unit-ID» " , this )
adView?. setListener ( this )
// Stretch to the width of the screen for banners to be fully functional
val width = ViewGroup.LayoutParams.MATCH_PARENT
// Banner height on phones and tablets is 50 and 90, respectively
val heightPx = resources. getDimensionPixelSize (R.dimen.banner_height)
adView?.layoutParams = FrameLayout. LayoutParams (width, heightPx)
// Set background or background color for banners to be fully functional
adView?. setBackgroundColor ( .. .)
val rootView = findViewById <ViewGroup>(android.R.id.content)
override fun onAdLoaded (maxAd: MaxAd) {}
override fun onAdLoadFailed (adUnitId: String?, error: MaxError?) {}
override fun onAdDisplayFailed (ad: MaxAd?, error: MaxError?) {}
override fun onAdClicked (maxAd: MaxAd) {}
override fun onAdExpanded (maxAd: MaxAd) {}
override fun onAdCollapsed (maxAd: MaxAd) {}
override fun onAdDisplayed (maxAd: MaxAd) { /* use this for impression tracking */ }
override fun onAdHidden (maxAd: MaxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
public class ExampleActivity extends Activity
implements MaxAdViewAdListener
private MaxAdView adView ;
adView = new MaxAdView ( " «ad-unit-ID» " , MaxAdFormat . MREC , this ) ;
adView . setListener ( this ) ;
// MREC width and height are 300 and 250 respectively, on phones and tablets
int widthPx = AppLovinSdkUtils . dpToPx ( this , 300 ) ;
int heightPx = AppLovinSdkUtils . dpToPx ( this , 250 ) ;
adView . setLayoutParams ( new FrameLayout. LayoutParams ( widthPx, heightPx ) ) ;
// Set background or background color for MRECs to be fully functional
adView . setBackgroundColor ( ... ) ;
ViewGroup rootView = findViewById ( android . R . id . content ) ;
rootView . addView ( adView ) ;
public void onAdLoaded ( final MaxAd maxAd ) {}
public void onAdLoadFailed ( final String adUnitId , final int errorCode ) {}
public void onAdDisplayFailed ( final MaxAd maxAd , final MaxError error ) {}
public void onAdClicked ( final MaxAd maxAd ) {}
public void onAdExpanded ( final MaxAd maxAd ) {}
public void onAdCollapsed ( final MaxAd maxAd ) {}
public void onAdDisplayed ( final MaxAd maxAd ) { /* use this for impression tracking */ }
public void onAdHidden ( final MaxAd maxAd ) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
class ExampleActivity : Activity(), MaxAdViewAdListener
private var adView: MaxAdView? = null
adView = MaxAdView ( " «ad-unit-ID» " , MaxAdFormat.MREC, this )
adView?. setListener ( this )
// MREC width and height are 300 and 250 respectively, on phones and tablets
val widthPx = AppLovinSdkUtils. dpToPx ( this , 300 )
val heightPx = AppLovinSdkUtils. dpToPx ( this , 250 )
adView?.layoutParams = FrameLayout. LayoutParams (widthPx, heightPx)
// Set background or background color for MRECs to be fully functional
adView?. setBackgroundColor ( .. .)
val rootView = findViewById <ViewGroup>(android.R.id.content)
override fun onAdLoaded (maxAd: MaxAd) {}
override fun onAdLoadFailed (adUnitId: String?, error: MaxError?) {}
override fun onAdDisplayFailed (ad: MaxAd?, error: MaxError?) {}
override fun onAdClicked (maxAd: MaxAd) {}
override fun onAdExpanded (maxAd: MaxAd) {}
override fun onAdCollapsed (maxAd: MaxAd) {}
override fun onAdDisplayed (maxAd: MaxAd) { /* use this for impression tracking */ }
override fun onAdHidden (maxAd: MaxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
在 Layout Editor 中加载和展示横幅或 MREC
您也可以将 MAX 横幅或 MREC 广告添加到视图布局 XML 中。
设置背景或背景色 (android:background
),确保广告功能齐全。
如果是横幅,请将宽度 (android:layout_width
) 拉伸至与屏幕相同的宽度。
对于 MREC,请相应地设置 android:adFormat
:
< com.applovin.mediation.ads.MaxAdView
xmlns:maxads = " http://schemas.applovin.com/android/1.0 "
maxads:adUnitId = " «ad-unit-ID» "
android:background = " @color/banner_background_color "
android:layout_width = " match_parent "
android:layout_height = " @dimen/banner_height " />
< com.applovin.mediation.ads.MaxAdView
xmlns:maxads = " http://schemas.applovin.com/android/1.0 "
maxads:adUnitId = " «ad-unit-ID» "
android:background = " @color/mrec_background_color "
android:layout_width = " 300dp "
android:layout_height = " 250dp " />
在 res/values/attrs.xml
中声明基础横幅高度为 50dp:
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< dimen name = " banner_height " > 50dp </ dimen >
在 res/values-sw600dp/attrs.xml
中声明平板电脑横幅高度为 90dp:
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< dimen name = " banner_height " > 90dp </ dimen >
要隐藏横幅或 MREC 广告,请进行如下调用:
adView . setVisibility ( View . GONE ) ;
adView . stopAutoRefresh () ;
adView.visibility = View.GONE
要显示横幅或 MREC 广告,请进行以下调用:
adView . setVisibility ( View . VISIBLE ) ;
adView . startAutoRefresh () ;
adView.visibility = View.VISIBLE
adView. startAutoRefresh ()
选择要集成的广告平台
选择要集成的广告平台,
然后按照具体说明操作。
添加您的 Google 竞价和 Google AdMob / Google Ad Manager 应用 ID
在应用的 AndroidManifest.xml
中,在 <application>
标签内添加一个 <meta-data>
标签
。以下示例展示了此标签的正确属性。
请用您的 Google 竞价和 Google AdMob / Google Ad Manager 应用 ID 替换 «your-admob-app-id»
。
<? xml version = " 1.0 " encoding = " utf-8 " ?>
android:name = " com.google.android.gms.ads.APPLICATION_ID "
android:value = " «your-admob-app-id» " />
Gradle 错误
Google AdMob 需要Android Gradle 插件 4.2.0 或更高版本,Gradle 6.7.1 或更高版本。
如果看到以下错误信息,请更新 Android Gradle 插件和 Gradle 版本:
AAPT: error: unexpected element <property> found in <manifest><application>.
compileSdkVersion
Google 移动广告 SDK 23.1.0 及更新版本要求 compileSdkVersion
为 34 或更高。
在应用的 build.gradle
中将 compileSdkVersion
设置为 34
或更高。
请参阅 Google 移动广告 SDK 发行说明 ,了解最新的 compileSdkVersion
要求。
初始化 Amazon SDK
Amazon Publisher Services SDK 需要在 MAX SDK 之外进行初始化:
// Amazon requires an 'Activity' instance
AdRegistration . getInstance ( " AMAZON_APP_ID " , this ) ;
AdRegistration . setAdNetworkInfo ( new DTBAdNetworkInfo ( DTBAdNetwork . MAX ) ) ;
AdRegistration . setMRAIDSupportedVersions ( new String [] { " 1.0 " , " 2.0 " , " 3.0 " } ) ;
AdRegistration . setMRAIDPolicy ( MRAIDPolicy . CUSTOM ) ;
从 Amazon SDK 加载横幅或 MREC 广告
要在 MAX 中集成 Amazon 广告,则必须先加载 Amazon 广告。
在加载 MAX 广告之前,将 DTBAdResponse
或 AdError
传递至 MaxAdView
实例。
为此,可以调用 MaxAdView#setLocalExtraParameter()
。
if ( AppLovinSdkUtils . isTablet ( getApplicationContext () ) )
amazonAdSlotId = " «Amazon-leader-slot-ID» " ;
adFormat = MaxAdFormat . LEADER ;
amazonAdSlotId = " «Amazon-banner-slot-ID» " ;
adFormat = MaxAdFormat . BANNER ;
// Raw size will be 320x50 for BANNERs on phones, and 728x90 for LEADERs on tablets
AppLovinSdkUtils . Size rawSize = adFormat . getSize () ;
DTBAdSize size = new DTBAdSize ( rawSize .getWidth () , rawSize .getHeight () , amazonAdSlotId ) ;
DTBAdRequest adLoader = new DTBAdRequest () ;
adLoader . setSizes ( size ) ;
adLoader . loadAd ( new DTBAdCallback ()
public void onSuccess ( @ NonNull final DTBAdResponse dtbAdResponse )
// 'adView' is your instance of MaxAdView
adView . setLocalExtraParameter ( " amazon_ad_response " , dtbAdResponse ) ;
public void onFailure ( @ NonNull final AdError adError )
// 'adView' is your instance of MaxAdView
adView . setLocalExtraParameter ( " amazon_ad_error " , adError ) ;
class ExampleActivity : Activity()
private val adView: MaxAdView? = null
val amazonAdSlotId: String
val adFormat: MaxAdFormat
if (AppLovinSdkUtils. isTablet (applicationContext))
amazonAdSlotId = " «Amazon-leader-slot-ID» "
adFormat = MaxAdFormat.LEADER
amazonAdSlotId = " «Amazon-banner-slot-ID» "
adFormat = MaxAdFormat.BANNER
// Raw size will be 320x50 for BANNERs on phones, and 728x90 for LEADERs on tablets
val rawSize = adFormat.size
val size = DTBAdSize (rawSize.width, rawSize.height, amazonAdSlotId)
val adLoader = DTBAdRequest ()
adLoader. loadAd ( object : DTBAdCallback
override fun onSuccess (dtbAdResponse: DTBAdResponse)
// 'adView' is your instance of MaxAdView
adView?. setLocalExtraParameter ( "amazon_ad_response" , dtbAdResponse)
override fun onFailure (adError: AdError)
// 'adView' is your instance of MaxAdView
adView?. setLocalExtraParameter ( "amazon_ad_error" , adError)
DTBAdRequest adLoader = new DTBAdRequest () ;
adLoader . setSizes ( new DTBAdSize ( 300 , 250 , amazonAdSlotId ) ) ;
adLoader . loadAd ( new DTBAdCallback ()
public void onSuccess ( @ NonNull final DTBAdResponse dtbAdResponse )
// 'adView' is your instance of MaxAdView
adView . setLocalExtraParameter ( " amazon_ad_response " , dtbAdResponse ) ;
public void onFailure ( @ NonNull final AdError adError )
// 'adView' is your instance of MaxAdView
adView . setLocalExtraParameter ( " amazon_ad_error " , adError ) ;
class ExampleActivity : Activity()
private val adView: MaxAdView? = null
val amazonAdSlotId: String
val adLoader = DTBAdRequest ()
adLoader. setSizes ( DTBAdSize ( 300 , 250 , amazonAdSlotId))
adLoader. loadAd ( object : DTBAdCallback
override fun onSuccess (dtbAdResponse: DTBAdResponse)
// 'adView' is your instance of MaxAdView
adView !! . setLocalExtraParameter ( "amazon_ad_response" , dtbAdResponse)
override fun onFailure (adError: AdError)
// 'adView' is your instance of MaxAdView
adView !! . setLocalExtraParameter ( "amazon_ad_error" , adError)
从 Amazon SDK 加载插屏广告
要将 Amazon 插屏广告集成到 MAX,必须先加载 Amazon 广告。
在加载 MAX 广告之前,将 DTBAdResponse
或 AdError
传递至 MaxInterstitialAd
实例。
您可以通过调用 MaxInterstitialAd#setLocalExtraParameter()
来完成此操作。
private static MaxInterstitialAd interstitialAd ; // static to ensure only one instance exists
private static boolean isFirstLoad = true ;
if ( interstitialAd == null )
interstitialAd = new MaxInterstitialAd ( " «MAX-inter-ad-unit-ID» " , this ) ;
DTBAdRequest adLoader = new DTBAdRequest () ;
adLoader . setSizes ( new DTBAdSize. DTBInterstitialAdSize ( " «Amazon-inter-slot-ID» " ) ) ;
adLoader . loadAd ( new DTBAdCallback ()
public void onSuccess ( @ NonNull final DTBAdResponse dtbAdResponse )
// 'interstitialAd' is your instance of MaxInterstitialAd
interstitialAd . setLocalExtraParameter ( " amazon_ad_response " , dtbAdResponse ) ;
public void onFailure ( @ NonNull final AdError adError )
// 'interstitialAd' is your instance of MaxInterstitialAd
interstitialAd . setLocalExtraParameter ( " amazon_ad_error " , adError ) ;
class ExampleActivity : Activity()
private var interstitialAd: MaxInterstitialAd? = null // static to ensure only one instance exists
private var isFirstLoad = true
if (interstitialAd == null )
interstitialAd = MaxInterstitialAd ( " «MAX-inter-ad-unit-ID» " , this )
val adLoader = DTBAdRequest ()
adLoader. setSizes (DTBAdSize. DTBInterstitialAdSize ( " «Amazon-inter-slot-ID» " ))
adLoader. loadAd ( object : DTBAdCallback
override fun onSuccess (dtbAdResponse: DTBAdResponse)
// 'interstitialAd' is your instance of MaxInterstitialAd
interstitialAd !! . setLocalExtraParameter ( "amazon_ad_response" , dtbAdResponse)
interstitialAd !! . loadAd ()
override fun onFailure (adError: AdError)
// 'interstitialAd' is your instance of MaxInterstitialAd
interstitialAd !! . setLocalExtraParameter ( "amazon_ad_error" , adError)
interstitialAd !! . loadAd ()
interstitialAd !! . loadAd ()
从 Amazon SDK 加载视频插屏广告
要在 MAX 中集成 Amazon 视频插屏广告,必须先加载 Amazon 广告。
在加载 MAX 广告之前,将 DTBAdResponse
或 AdError
传递至 MaxInterstitialAd
实例。
您可以通过调用 MaxInterstitialAd#setLocalExtraParameter()
来完成此操作。
private static MaxInterstitialAd interstitialAd ; // static to ensure only one instance exists
private static boolean isFirstLoad = true ;
if ( interstitialAd == null )
interstitialAd = new MaxInterstitialAd ( " «MAX-inter-ad-unit-ID» " , this ) ;
DTBAdRequest adLoader = new DTBAdRequest () ;
// Switch video player width and height values(320, 480) depending on device orientation
adLoader . setSizes ( new DTBAdSize. DTBVideo ( 320 , 480 , " «Amazon-video-inter-slot-ID» " ) ) ;
adLoader . loadAd ( new DTBAdCallback ()
public void onSuccess ( @ NonNull final DTBAdResponse dtbAdResponse )
// 'interstitialAd' is your instance of MaxInterstitialAd
interstitialAd . setLocalExtraParameter ( " amazon_ad_response " , dtbAdResponse ) ;
public void onFailure ( @ NonNull final AdError adError )
// 'interstitialAd' is your instance of MaxInterstitialAd
interstitialAd . setLocalExtraParameter ( " amazon_ad_error " , adError ) ;
class ExampleActivity : Activity()
private var interstitialAd: MaxInterstitialAd? = null // static to ensure only one instance exists
private var isFirstLoad = true
if (interstitialAd == null )
interstitialAd = MaxInterstitialAd ( " «MAX-inter-ad-unit-iD» " , this )
val adLoader = DTBAdRequest ()
// Switch video player width and height values(320, 480) depending on device orientation
adLoader. setSizes (DTBAdSize. DTBVideo ( 320 , 480 , " «Amazon-video-inter-slot-ID» " ))
adLoader. loadAd ( object : DTBAdCallback
override fun onSuccess (dtbAdResponse: DTBAdResponse)
// 'interstitialAd' is your instance of MaxInterstitialAd
interstitialAd !! . setLocalExtraParameter ( "amazon_ad_response" , dtbAdResponse)
interstitialAd !! . loadAd ()
override fun onFailure (adError: AdError)
// 'interstitialAd' is your instance of MaxInterstitialAd
interstitialAd !! . setLocalExtraParameter ( "amazon_ad_error" , adError)
interstitialAd !! . loadAd ()
interstitialAd !! . loadAd ()
从 Amazon SDK 加载激励视频广告
要在 MAX 中集成 Amazon 激励视频广告,请先加载 Amazon 广告。
在加载 MAX 广告之前,将 DTBAdResponse
或 AdError
传递至 MaxRewardedAd
实例。
您可以通过调用 MaxRewardedAd#setLocalExtraParameter()
来完成此操作。
private static MaxRewardedAd rewardedAd ; // static to ensure only one instance exists
private static boolean isFirstLoad = true ;
if ( rewardedAd == null )
rewardedAd = MaxRewardedAd . getInstance ( " «MAX-rewarded-ad-unit-ID» " , this ) ;
DTBAdRequest adLoader = new DTBAdRequest () ;
// Switch video player width and height values(320, 480) depending on device orientation
adLoader . setSizes ( new DTBAdSize. DTBVideo ( 320 , 480 , " «Amazon-video-rewarded-slot-ID» " ) ) ;
adLoader . loadAd ( new DTBAdCallback ()
public void onSuccess ( @ NonNull final DTBAdResponse dtbAdResponse )
// 'rewardedAd' is your instance of MaxRewardedAd
rewardedAd . setLocalExtraParameter ( " amazon_ad_response " , dtbAdResponse ) ;
public void onFailure ( @ NonNull final AdError adError )
// 'rewardedAd' is your instance of MaxRewardedAd
rewardedAd . setLocalExtraParameter ( " amazon_ad_error " , adError ) ;
private static MaxRewardedAd rewardedAd; // static to ensure only one instance exists
private static boolean isFirstLoad = true ;
if ( rewardedAd == null )
rewardedAd = MaxRewardedAd. getInstance ( " «MAX-rewarded-ad-unit-ID» " , this );
DTBAdRequest adLoader = new DTBAdRequest ();
// Switch video player width and height values(320, 480) depending on device orientation
adLoader. setSizes ( new DTBAdSize. DTBVideo ( 320 , 480 , " «Amazon-video-rewarded-slot-ID» " ) );
adLoader. loadAd ( new DTBAdCallback ()
public void onSuccess (@NonNull final DTBAdResponse dtbAdResponse)
// 'rewardedAd' is your instance of MaxRewardedAd
rewardedAd. setLocalExtraParameter ( "amazon_ad_response" , dtbAdResponse );
public void onFailure (@NonNull final AdError adError)
// 'rewardedAd' is your instance of MaxRewardedAd
rewardedAd. setLocalExtraParameter ( "amazon_ad_error" , adError );
测试 Amazon Publisher Services
AppLovin 建议您为 Amazon SDK 启用测试模式,
以便接收测试广告。
通过进行以下调用来启用测试模式:
AdRegistration . enableTesting ( true ) ;
AdRegistration . enableLogging ( true ) ;
您可以过滤瀑布流,使其只包含 Amazon 广告。
为此,请在Mediation Debugger 中选择Select Live Network ,然后选择 Amazon 平台。
Meta Audience Network 数据处理选项
如果您不想启用限制数据使用 (LDU) 模式,请向 SetDataProcessingOptions()
传递一个空字符串数组:
import com.facebook.ads.AdSettings ;
AdSettings . setDataProcessingOptions ( new String [] {} ) ;
import com.facebook.ads.AdSettings
AdSettings. setDataProcessingOptions ( arrayOf <String>() )
要为用户启用 LDU 并指定用户地理位置,请以如下形式调用 SetDataProcessingOptions()
:
import com.facebook.ads.AdSettings ;
AdSettings . setDataProcessingOptions ( new String [] { " LDU " }, «country» , «state» ) ;
import com.facebook.ads.AdSettings
AdSettings. setDataProcessingOptions ( arrayOf ( "LDU" ), «country» , «state» )
使用 Google UMP
如果您使用 Google UMP 作为 CMP,则可以判断用户是否已向 Meta 授予许可。
为此,请使用如下代码:
Boolean hasMetaConsent = AppLovinPrivacySettings . getAdditionalConsentStatus ( 89 ) ;
if ( hasMetaConsent != null )
// Set Meta Data Processing Options accordingly.
// AC String is not available on disk. Please check for consent status after the user completes the CMP flow.
val hasMetaConsent = AppLovinPrivacySettings. getAdditionalConsentStatus ( 89 )
if ( hasMetaConsent != null )
// Set Meta Data Processing Options accordingly.
// AC String is not available on disk. Please check for consent status after the user completes the CMP flow.
Meta Audience Network 加利福尼亚州用户的数据处理选项
要了解如何启用 Meta Audience Network 的 “Limited Data Use”(限制数据使用)标记,请参阅Meta 开发者文档 。
Android Manifest 合并错误
一些平台 SDK 会在其打包的 Android Manifest 文件中使用 <queries>
元素。
如果使用的 Android Gradle 插件版本不兼容,则会导致以下编译错误之一:
com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
error: unexpected element <queries> found in <manifest>.
Missing 'package' key attribute on element package at [:com.my.target.mytarget-sdk-5.11.3:]
AndroidManifest Validation failed
要修复此错误,请升级至以下 Android Gradle 插件版本之一。
这些版本支持 <queries>
元素:
当前 Android Gradle 插件版本 支持 <queries>
元素的版本 4.1.* 全部 4.0.* 4.0.1+ 3.6.* 3.6.4+ 3.5.* 3.5.4+ 3.4.* 3.4.3+ 3.3.* 3.3.3+
手动下载 MAX 的广告平台