Android SDK Version
All Implemented Interfaces:

public class NativeAd
extends NativeAdBase
NativeAd provides ad creative for apps to rendered in custom layout.
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.
Since:
4.6
Nested Class Summary
Modifier and TypeClass and Description
static class NativeAd.AdCreativeType 
Constructor Summary
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.
Method Summary
Modifier and TypeMethod and Description
NativeAd.AdCreativeTypegetAdCreativeType()
Gets the Ad Creative Type, which can be IMAGE, VIDEO, CAROUSEL or UNKNOWN.
com.facebook.ads.internal.api.NativeAdApigetNativeAdApi()
Used by other SDK classes and subject to change.
voidregisterViewForInteraction(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.
voidregisterViewForInteraction(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.
voidregisterViewForInteraction(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.
voidregisterViewForInteraction(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.
voidregisterViewForInteraction(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.
voidregisterViewForInteraction(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.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail

NativeAd

public NativeAd(Context context,
                java.lang.String placementId)
Constructs an NativeAd using the given context and placement id.
Parameters:
context - Android context
placementId - id of ad placement
Since:
4.6

NativeAd

public NativeAd(Context context,
                com.facebook.ads.internal.api.NativeAdBaseApi nativeAdBaseApi)
Used by other SDK classes and subject to change.

NativeAd

public NativeAd(Context context,
                NativeAdBase other)
Used by other SDK classes and subject to change.
Since:
4.6
Method Detail

getNativeAdApi

public com.facebook.ads.internal.api.NativeAdApi getNativeAdApi()
Used by other SDK classes and subject to change.

getAdCreativeType

public NativeAd.AdCreativeType getAdCreativeType()
Gets the Ad Creative Type, which can be IMAGE, VIDEO, CAROUSEL or UNKNOWN.
Returns:
the NativeAd.AdCreativeType of the current Native Ad if the ad is loaded. Otherwise returns UNKNOWN.

registerViewForInteraction

public 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. MediaView must be within the view passed as the container for this NativeAd. Applies a click handler to the entire unit.
Parameters:
view - the View containing this NativeAd for display
mediaView - MediaView to display contents such as video, carousel, etc.
Since:
4.99

registerViewForInteraction

public 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. MediaView must be within the view passed as the container for this NativeAd. Applies a click handler to the entire unit.
Parameters:
view - the View containing this NativeAd for display
mediaView - MediaView to display contents such as video, carousel, etc.
adIconView - optional MediaView to display Icon.
Since:
4.99

registerViewForInteraction

public 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. MediaView must be within the view passed as the container for this NativeAd. Applies a click handler to the entire unit.
Parameters:
view - the View containing this NativeAd for display
mediaView - MediaView to display contents such as video, carousel, etc.
clickableViews - a list of all view elements that should handle taps on this unit
Since:
4.99

registerViewForInteraction

public 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. MediaView must be within the view passed as the container for this NativeAd. Applies a click handler to the entire unit.
Parameters:
view - the View containing this NativeAd for display
mediaView - 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 unit
Since:
4.99

registerViewForInteraction

public 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. MediaView must be within the view passed as the container for this NativeAd. Applies a click handler to the entire unit. We recommend use MediaView for ad icon, but for Mediation platform users, ImageView is also supported for Native Ad's ad Icon.
Parameters:
view - the View containing this NativeAd for display
mediaView - MediaView to display contents such as video, carousel, etc.
iconView - optional imageView for ad Icon.
Since:
5.0

registerViewForInteraction

public 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. MediaView must be within the view passed as the container for this NativeAd. Applies a click handler to the entire unit. We recommend use MediaView for ad icon, but for Mediation platform users, ImageView is also supported for Native Ad's ad Icon.
Parameters:
view - the View containing this NativeAd for display
mediaView - 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
Since:
5.0