Android SDK Version
  • java.lang.Object
    • com.facebook.ads.NativeAdBase
All Implemented Interfaces:
Direct Known Subclasses:

public abstract class NativeAdBase
extends java.lang.Object
implements Ad
Since:
4.99
Nested Class Summary
Modifier and TypeClass and Description
static class NativeAdBase.Image
Image creative.
static class NativeAdBase.MediaCacheFlag
Media Cache flag
static class NativeAdBase.NativeComponentTag
Optional tags for native ad view components.
static class NativeAdBase.Rating
Rating info.
Constructor Summary
Constructor and Description
NativeAdBase(Context context, java.lang.String placementId)
Constructs an NativeAdBase using the given context and placement id.
NativeAdBase(com.facebook.ads.internal.api.NativeAdBaseApi nativeAdBaseApi)
Used by other SDK classes and subject to change.
Method Summary
Modifier and TypeMethod and Description
voiddestroy()
Destroys the ad control.
voiddownloadMedia()
Manually pre-cache media contents such as Image, Icon, video, etc.
static NativeAdBasefromBidPayload(Context context, java.lang.String placementId, java.lang.String bidPayload) 
java.lang.StringgetAdBodyText()
Gets the body, usually a longer description of the ad.
java.lang.StringgetAdCallToAction()
Gets the call to action phrase.
NativeAdBase.ImagegetAdChoicesIcon() 
java.lang.StringgetAdChoicesImageUrl() 
java.lang.StringgetAdChoicesLinkUrl() 
java.lang.StringgetAdChoicesText() 
NativeAdBase.ImagegetAdCoverImage()
Gets the cover image creative.
java.lang.StringgetAdHeadline()
Shows the headline that the advertiser entered when they created an ad; main title of an ad.
NativeAdBase.ImagegetAdIcon()
Gets the icon creative.
java.lang.StringgetAdLinkDescription()
Shows additional information that the advertiser may have entered.
java.lang.StringgetAdSocialContext()
Gets the social context.
NativeAdBase.RatinggetAdStarRating()
Deprecated. 
Star rating is deprecated.
java.lang.StringgetAdTranslation()
Shows the word 'ad', translated into the regional language
java.lang.StringgetAdUntrimmedBodyText()
Gets the untrimmed ad body
java.lang.StringgetAdvertiserName()
Shows the name of Facebook Page or mobile app that represents the ad.
NativeAdViewAttributesgetAdViewAttributes()
Deprecated. 
java.lang.StringgetId()
Gets a unique ID for the NativeAd.
com.facebook.ads.internal.api.NativeAdBaseApigetInternalNativeAd()
Used by other SDK classes and subject to change.
java.lang.StringgetPlacementId()
Get the placementId for this ad.
java.lang.StringgetPromotedTranslation()
Shows the word 'promoted', translated into the regional language
java.lang.StringgetSponsoredTranslation()
Shows the word 'Sponsored', translated into the regional language.
booleanhasCallToAction()
Gets whether an action or command is present in an ad
booleanisAdInvalidated()
Indicate whether the ad is still valid.
booleanisAdLoaded()
Gets whether an ad is loaded and ready to show.
booleanisNativeConfigEnabled()
Deprecated. 
voidloadAd()
Loads an ad.
voidloadAd(NativeAdBase.MediaCacheFlag mediaCacheFlag)
This method allows to disable pre-caching for the ads while loadAd() pre-cache ad assets by default.
voidloadAdFromBid(java.lang.String bidPayload)
Loads an ad from the payload supplied with a bid.
voidloadAdFromBid(java.lang.String bidPayload, NativeAdBase.MediaCacheFlag mediaCacheFlag) 
voidonCtaBroadcast() 
voidsetAdListener(NativeAdListener adListener) 
voidsetExtraHints(ExtraHints extraHints) 
voidsetOnTouchListener(View.OnTouchListener touchListener)
Sets an OnTouchListener to be notified of touch events on the ad unit.
voidunregisterView() 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail

NativeAdBase

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

NativeAdBase

public NativeAdBase(com.facebook.ads.internal.api.NativeAdBaseApi nativeAdBaseApi)
Used by other SDK classes and subject to change.
Method Detail

fromBidPayload

public static NativeAdBase fromBidPayload(Context context,
                                          java.lang.String placementId,
                                          java.lang.String bidPayload)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

getInternalNativeAd

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

setAdListener

public void setAdListener(NativeAdListener adListener)
Parameters:
adListener -
Since:
4.6

setExtraHints

public void setExtraHints(ExtraHints extraHints)
Specified by:
setExtraHints in interface Ad

loadAd

public void loadAd()
Description copied from interface: Ad
Loads an ad.
This method always returns immediately. The ad is loaded asynchronously. The control's ad listener will be called when loading finishes or fails.
Specified by:
loadAd in interface Ad
Since:
4.6

loadAd

public void loadAd(NativeAdBase.MediaCacheFlag mediaCacheFlag)
This method allows to disable pre-caching for the ads while loadAd() pre-cache ad assets by default. However, please be aware that once you disable pre-caching, there is a risk that ad assets might not be loaded in time when an ads is shown at some cases like unstable internet connection, etc. As an impression will not be logged until ad media contents are properly shown, failure to load ad assets in time might result in lagging an impression even if adView is visible (and possibly not getting an impression at worst case). In order to check if an impression is logged or not, please look at AdListener.onLoggingImpression(Ad)
Parameters:
mediaCacheFlag - pre-cache option for ad assets.
Since:
4.6

loadAdFromBid

public void loadAdFromBid(java.lang.String bidPayload)
Description copied from interface: Ad
Loads an ad from the payload supplied with a bid.
This method always returns immediately. The ad is loaded asynchronously. If available, the ad listener will be called when loading finishes or fails.
Specified by:
loadAdFromBid in interface Ad
Parameters:
bidPayload - The payload supplied with the bid

loadAdFromBid

public void loadAdFromBid(java.lang.String bidPayload,
                          NativeAdBase.MediaCacheFlag mediaCacheFlag)

downloadMedia

public void downloadMedia()
Manually pre-cache media contents such as Image, Icon, video, etc. If you requests an ads with MediaCacheFlag.ALL, this does not need to be called at all. loadAd() set MediaCacheFlag.ALL by default. However, if you disabled pre-cache by setting MediaCacheFlag.NONE, then this method needs to be called before registerViewForInteraction(). Otherwise, you have a risk not getting an impression. For more detail, please look at loadAd(MediaCacheFlag)

destroy

public void destroy()
Description copied from interface: Ad
Destroys the ad control.
This method should be called when the hosting activity of the ad control is destroyed.
Specified by:
destroy in interface Ad

getPlacementId

public java.lang.String getPlacementId()
Description copied from interface: Ad
Get the placementId for this ad.
Specified by:
getPlacementId in interface Ad
Returns:
placementId String representing the placementId for this ad.

isAdInvalidated

public boolean isAdInvalidated()
Description copied from interface: Ad
Indicate whether the ad is still valid.
Specified by:
isAdInvalidated in interface Ad
Returns:
true if the ad is not valid anymore.

isAdLoaded

public boolean isAdLoaded()
Gets whether an ad is loaded and ready to show.
Returns:
whether an ad is loaded
Since:
4.6

isNativeConfigEnabled

@Deprecated
public boolean isNativeConfigEnabled()
Deprecated. 
Gets whether ad config settings are enabled or not
Returns:
whether ad config settings are loaded
Since:
4.6

hasCallToAction

public boolean hasCallToAction()
Gets whether an action or command is present in an ad
Returns:
True if CAT is not present

getAdIcon

public NativeAdBase.Image getAdIcon()
Gets the icon creative.
Returns:
the ad icon
Since:
4.6

getAdCoverImage

public NativeAdBase.Image getAdCoverImage()
Gets the cover image creative.
Returns:
the ad cover image
Since:
4.6

getAdViewAttributes

@Deprecated
public NativeAdViewAttributes getAdViewAttributes()
Deprecated. 
Gets the ad configuration settings.
Returns:
the ad configuration settings
Since:
4.6

getAdvertiserName

public java.lang.String getAdvertiserName()
Shows the name of Facebook Page or mobile app that represents the ad.
Returns:
the advertiser's name

getAdHeadline

public java.lang.String getAdHeadline()
Shows the headline that the advertiser entered when they created an ad; main title of an ad.
Returns:
the ad Headline

getAdBodyText

public java.lang.String getAdBodyText()
Gets the body, usually a longer description of the ad. This field is trimmed if text is too long.
Returns:
the ad body

getAdUntrimmedBodyText

public java.lang.String getAdUntrimmedBodyText()
Gets the untrimmed ad body
Returns:
the untrimmed ad body

getAdCallToAction

public java.lang.String getAdCallToAction()
Gets the call to action phrase.
Returns:
the call to action phrase
Since:
4.6

getAdSocialContext

public java.lang.String getAdSocialContext()
Gets the social context.
Returns:
the social content sentence
Since:
4.6

getAdLinkDescription

public java.lang.String getAdLinkDescription()
Shows additional information that the advertiser may have entered.
Returns:
the link description of an ad.

getSponsoredTranslation

public java.lang.String getSponsoredTranslation()
Shows the word 'Sponsored', translated into the regional language.
Returns:
Sponsored label in regional language

getAdTranslation

public java.lang.String getAdTranslation()
Shows the word 'ad', translated into the regional language
Returns:
ad label in regional language

getPromotedTranslation

public java.lang.String getPromotedTranslation()
Shows the word 'promoted', translated into the regional language
Returns:
promoted label in regional language

getAdStarRating

@Deprecated
public NativeAdBase.Rating getAdStarRating()
Deprecated. Star rating is deprecated.
Gets the star rating.
Returns:
the star rating
Since:
4.6

getId

public java.lang.String getId()
Gets a unique ID for the NativeAd.
Returns:
the unique ID
Since:
4.6

getAdChoicesIcon

public NativeAdBase.Image getAdChoicesIcon()
Returns:
Since:
4.6

getAdChoicesImageUrl

public java.lang.String getAdChoicesImageUrl()

getAdChoicesLinkUrl

public java.lang.String getAdChoicesLinkUrl()
Returns:
Since:
4.6

getAdChoicesText

public java.lang.String getAdChoicesText()
Since:
4.28

onCtaBroadcast

public void onCtaBroadcast()
Since:
4.28

unregisterView

public void unregisterView()
Since:
4.6

setOnTouchListener

public void setOnTouchListener(View.OnTouchListener touchListener)
Sets an OnTouchListener to be notified of touch events on the ad unit. Touchable views that can trigger this listener are either the click-able views if a set was provided in registerViewForInteraction(), or the container view provided to registerViewForInteraction() and all of the container's sub-views.
Parameters:
touchListener - the touch listener
Since:
4.6