public class NativeAd extends java.lang.Object implements Ad
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 registerViewForInteraction(android.view.View viewContainer)
to handle logging of ad impressions and clicks.
Modifier and Type | Class and Description |
---|---|
static class |
NativeAd.Image
Image creative.
|
static class |
NativeAd.MediaCacheFlag
Media Cache flag
|
static class |
NativeAd.Rating
Rating info.
|
Constructor and Description |
---|
NativeAd(android.content.Context context,
NativeAdapter adapter,
AdPlacementDefinition placementDefinition) |
NativeAd(android.content.Context context,
java.lang.String placementId)
Constructs an NativeAd using the given context and placement id.
|
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Destroys the ad control.
|
static void |
downloadAndDisplayImage(NativeAd.Image image,
android.widget.ImageView imageView)
Downloads the given Image and displays it in the given ImageView.
|
java.lang.String |
getAdBody()
Gets the body, usually a longer description of the ad.
|
java.lang.String |
getAdCallToAction()
Gets the call to action phrase.
|
NativeAd.Image |
getAdChoicesIcon() |
java.lang.String |
getAdChoicesLinkUrl() |
NativeAd.Image |
getAdCoverImage()
Gets the cover image creative.
|
NativeAd.Image |
getAdIcon()
Gets the icon creative.
|
AdNetwork |
getAdNetwork()
Returns the enum for the ad network from which the ad has been loaded.
|
java.lang.String |
getAdSocialContext()
Gets the social context.
|
NativeAd.Rating |
getAdStarRating()
Deprecated.
Star rating is deprecated.
|
java.lang.String |
getAdSubtitle()
Gets the subtitle.
|
java.lang.String |
getAdTitle()
Gets the title.
|
NativeAdViewAttributes |
getAdViewAttributes()
Gets the ad configuration settings.
|
java.lang.String |
getId()
Gets a unique ID for the NativeAd.
|
java.lang.String |
getPlacementId()
Get the placementId for this ad.
|
boolean |
isAdLoaded()
Gets whether an ad is loaded and ready to show.
|
boolean |
isNativeConfigEnabled()
Gets whether ad config settings are enabled or not
|
void |
loadAd()
Loads an ad.
|
void |
loadAd(java.util.EnumSet<NativeAd.MediaCacheFlag> mediaCacheFlags) |
void |
registerViewForInteraction(android.view.View view)
Registers the given view as the container for this NativeAd to handle impressions and
clicks.
|
void |
registerViewForInteraction(android.view.View view,
java.util.List<android.view.View> clickableViews)
Registers the given view as the container for this NativeAd to handle impressions and
clicks.
|
void |
setAdListener(AdListener adListener) |
void |
setImpressionListener(ImpressionListener impListener)
Deprecated.
See
AbstractAdListener and setAdListener(com.facebook.ads.AdListener) .
Sets an ImpressionListener to be notified of impression events in ad control lifecycle. |
void |
setMediaViewAutoplay(boolean mediaViewAutoplay)
Deprecated.
Autoplay control will be moved to the server side.
This API will be removed in future SDK versions.
|
void |
setOnTouchListener(android.view.View.OnTouchListener touchListener)
Sets an OnTouchListener to be notified of touch events on the ad unit.
|
void |
unregisterView() |
protected static boolean |
viewIsRegisteredForInteraction(android.view.View view) |
public NativeAd(android.content.Context context, java.lang.String placementId)
context
- Android contextplacementId
- id of ad placementpublic NativeAd(android.content.Context context, NativeAdapter adapter, AdPlacementDefinition placementDefinition)
public static void downloadAndDisplayImage(NativeAd.Image image, android.widget.ImageView imageView)
image
- image to be downloadedimageView
- view to show the downloaded imagepublic void setAdListener(AdListener adListener)
@Deprecated public void setImpressionListener(ImpressionListener impListener)
AbstractAdListener
and setAdListener(com.facebook.ads.AdListener)
.
Sets an ImpressionListener to be notified of impression events in ad control lifecycle.impListener
- the listenerpublic AdNetwork getAdNetwork()
public void loadAd()
Ad
This method always returns immediately. The ad is loaded asynchronously. The control's ad listener will be called when loading finishes or fails.
public void loadAd(java.util.EnumSet<NativeAd.MediaCacheFlag> mediaCacheFlags)
public void destroy()
Ad
This method should be called when the hosting activity of the ad control is destroyed.
public java.lang.String getPlacementId()
Ad
getPlacementId
in interface Ad
public boolean isAdLoaded()
public boolean isNativeConfigEnabled()
public NativeAd.Image getAdIcon()
public NativeAd.Image getAdCoverImage()
public NativeAdViewAttributes getAdViewAttributes()
public java.lang.String getAdTitle()
public java.lang.String getAdSubtitle()
public java.lang.String getAdBody()
public java.lang.String getAdCallToAction()
public java.lang.String getAdSocialContext()
@Deprecated public NativeAd.Rating getAdStarRating()
public java.lang.String getId()
public NativeAd.Image getAdChoicesIcon()
public java.lang.String getAdChoicesLinkUrl()
public void registerViewForInteraction(android.view.View view)
view
- the View containing this NativeAd for displaypublic void registerViewForInteraction(android.view.View view, java.util.List<android.view.View> clickableViews)
view
- the View containing this NativeAd for displayclickableViews
- a list of all view elements that should handle taps on this unit@Deprecated public void setMediaViewAutoplay(boolean mediaViewAutoplay)
mediaViewAutoplay
- whether autoplay is enabled or notprotected static boolean viewIsRegisteredForInteraction(android.view.View view)
public void unregisterView()
public void setOnTouchListener(android.view.View.OnTouchListener touchListener)
touchListener
- the touch listener