With a few changes to your code, you can combine native and banner ads in your ad requests.
Prerequisites
- Complete the Get started guide .
Load an ad
To make a combined native and banner request, do the following:
-
Pass both
NativeAdType.NATIVEtype andNativeAdType.BANNERtype as a list in theNativeAdRequest. -
Set at least one banner ad size.
The following examples loads a combined native and banner ad:
Kotlin
val
adRequest
=
NativeAdRequest
.
Builder
(
AD_UNIT_ID
,
listOf
(
NativeAdType
.
NATIVE
,
NativeAdType
.
BANNER
))
// Use setAdSize() or setAdSizes() depending on if you want multiple ad sizes or not.
.
setAdSizes
(
listOf
(
AdSize
.
BANNER
,
AdSize
.
LARGE_BANNER
))
.
build
()
// Load the native and banner ad with the ad request and callback.
NativeAdLoader
.
load
(
adRequest
,
getNativeAdLoaderCallback
())
Java
NativeAdRequest
adRequest
=
new
NativeAdRequest
.
Builder
(
AD_UNIT_ID
,
List
.
of
(
NativeAdType
.
NATIVE
,
NativeAdType
.
BANNER
))
// Use setAdSize() or setAdSizes() depending on if you want multiple ad sizes or not.
.
setAdSizes
(
Arrays
.
asList
(
AdSize
.
BANNER
,
AdSize
.
LARGE_BANNER
))
.
build
();
// Load the native and banner ad with the ad request and callback.
NativeAdLoader
.
load
(
adRequest
,
getNativeAdLoaderCallback
());
Get the ad from the NativeAdLoaderCallback
object
Depending on which type of ad has successfully loaded, the NativeAdLoaderCallback
object calls the onNativeAdLoaded()
method for native
ads and the onBannerAdLoaded()
method for banner ads.
The following example gets banner or native ads:
Kotlin
private
fun
getNativeAdLoaderCallback
():
NativeAdLoaderCallback
{
return
object
:
NativeAdLoaderCallback
{
override
fun
onNativeAdLoaded
(
nativeAd
:
NativeAd
)
{
// Called when a native ad has loaded.
}
override
fun
onBannerAdLoaded
(
bannerAd
:
BannerAd
)
{
// Called when a banner ad has loaded.
}
}
}
Java
private
NativeAdLoaderCallback
getNativeAdLoaderCallback
()
{
return
new
NativeAdLoaderCallback
()
{
@Override
public
void
onNativeAdLoaded
(
@NonNull
NativeAd
nativeAd
)
{
// Called when a native ad has loaded.
}
@Override
public
void
onBannerAdLoaded
(
@NonNull
BannerAd
bannerAd
)
{
// Called when a banner ad has loaded.
}
};
}

