public class NativeAd extends NativeAdBase
To use NativeAd, do the following:
NativeAd nativeAd = new NativeAd(context, PLACEMENT_ID);
nativeAd.setAdListener(new AbstractAdListener() {
public void onAdLoaded(Ad ad) {
if (ad == nativeAd) {
// Renders the ad using creative properties
String adTitle = getAdTitle();
}
}
});
nativeAd.loadAd();
Before displaying the ad, call com.facebook.ads.NativeAd#registerViewForInteraction(
android.view.View viewContainer, MediaView mediaView)
to handle logging of ad impressions and
clicks.
Modifier and Type | Class and Description |
---|---|
static class |
NativeAd.AdCreativeType |
NativeAdBase.Image, NativeAdBase.MediaCacheFlag, NativeAdBase.NativeAdLoadConfigBuilder, NativeAdBase.NativeComponentTag, NativeAdBase.NativeLoadAdConfig, NativeAdBase.Rating
Ad.LoadAdConfig, Ad.LoadConfigBuilder
Constructor and Description |
---|
NativeAd(Context context,
NativeAdBase other)
Used by other SDK classes and subject to change.
|
NativeAd(Context context,
com.facebook.ads.internal.api.NativeAdBaseApi nativeAdBaseApi)
Used by other SDK classes and subject to change.
|
NativeAd(Context context,
java.lang.String placementId)
Constructs an NativeAd using the given context and placement id.
|
Modifier and Type | Method and Description |
---|---|
NativeAd.AdCreativeType |
getAdCreativeType()
Gets the Ad Creative Type, which can be IMAGE, VIDEO, CAROUSEL or UNKNOWN.
|
com.facebook.ads.internal.api.NativeAdApi |
getNativeAdApi()
Used by other SDK classes and subject to change.
|
void |
registerViewForInteraction(View view,
MediaView mediaView)
Registers the given view as the container and the required MediaView as the contents display
for this NativeAd to handle impressions and clicks.
|
void |
registerViewForInteraction(View view,
MediaView mediaView,
ImageView iconView)
Registers the given view as the container and the required MediaView as the contents display
for this NativeAd to handle impressions and clicks.
|
void |
registerViewForInteraction(View view,
MediaView mediaView,
ImageView iconView,
java.util.List<View> clickableViews)
Registers the given view as the container and the required MediaView as the contents display
for this NativeAd to handle impressions and clicks.
|
void |
registerViewForInteraction(View view,
MediaView mediaView,
java.util.List<View> clickableViews)
Registers the given view as the container and the required MediaView as the contents display
for this NativeAd to handle impressions and clicks.
|
void |
registerViewForInteraction(View view,
MediaView mediaView,
MediaView adIconView)
Registers the given view as the container and the required MediaView as the contents display
for this NativeAd to handle impressions and clicks.
|
void |
registerViewForInteraction(View view,
MediaView mediaView,
MediaView adIconView,
java.util.List<View> clickableViews)
Registers the given view as the container and the required MediaView as the contents display
for this NativeAd to handle impressions and clicks.
|
buildLoadAdConfig, destroy, downloadMedia, fromBidPayload, getAdBodyText, getAdCallToAction, getAdChoicesIcon, getAdChoicesImageUrl, getAdChoicesLinkUrl, getAdChoicesText, getAdCoverImage, getAdHeadline, getAdIcon, getAdLinkDescription, getAdSocialContext, getAdStarRating, getAdTranslation, getAdUntrimmedBodyText, getAdvertiserName, getAdViewAttributes, getAspectRatio, getId, getInternalNativeAd, getPlacementId, getPreloadedIconViewDrawable, getPromotedTranslation, getSponsoredTranslation, hasCallToAction, isAdInvalidated, isAdLoaded, isNativeConfigEnabled, loadAd, loadAd, onCtaBroadcast, setExtraHints, setOnTouchListener, unregisterView
public NativeAd(Context context, java.lang.String placementId)
context
- Android contextplacementId
- id of ad placementpublic NativeAd(Context context, com.facebook.ads.internal.api.NativeAdBaseApi nativeAdBaseApi)
public NativeAd(Context context, NativeAdBase other)
public com.facebook.ads.internal.api.NativeAdApi getNativeAdApi()
public NativeAd.AdCreativeType getAdCreativeType()
NativeAd.AdCreativeType
of the current Native Ad if the ad is loaded. Otherwise
returns UNKNOWN.public void registerViewForInteraction(View view, MediaView mediaView)
view
- the View containing this NativeAd for displaymediaView
- MediaView to display contents such as video, carousel, etc.public void registerViewForInteraction(View view, MediaView mediaView, MediaView adIconView)
view
- the View containing this NativeAd for displaymediaView
- MediaView to display contents such as video, carousel, etc.adIconView
- optional MediaView
to display Icon.public void registerViewForInteraction(View view, MediaView mediaView, java.util.List<View> clickableViews)
view
- the View containing this NativeAd for displaymediaView
- MediaView to display contents such as video, carousel, etc.clickableViews
- a list of all view elements that should handle taps on this unitpublic void registerViewForInteraction(View view, MediaView mediaView, MediaView adIconView, java.util.List<View> clickableViews)
view
- the View containing this NativeAd for displaymediaView
- MediaView to display contents such as video, carousel, etc.adIconView
- optional MediaView
to display Icon.clickableViews
- a list of all view elements that should handle taps on this unitpublic void registerViewForInteraction(View view, MediaView mediaView, ImageView iconView)
We recommend use MediaView
for ad icon, but for Mediation platform users, ImageView
is also supported for Native Ad's ad Icon.
view
- the View containing this NativeAd for displaymediaView
- MediaView to display contents such as video, carousel, etc.iconView
- optional imageView for ad Icon.public void registerViewForInteraction(View view, MediaView mediaView, ImageView iconView, java.util.List<View> clickableViews)
We recommend use MediaView
for ad icon, but for Mediation platform users, ImageView
is also supported for Native Ad's ad Icon.
view
- the View containing this NativeAd for displaymediaView
- MediaView to display contents such as video, carousel, etc.iconView
- optional imageView for ad Icon.clickableViews
- a list of all view elements that should handle taps on this unit