public class NativeAd extends Object implements Ad
NativeAd nativeAd = new NativeAd(context, PLACEMENT_ID);
nativeAd.setAdListener(new AdListener() {
public void onAdLoaded(Ad ad) {
if (ad == nativeAd) {
// Renders the ad using creative properties
String adTitle = getAdTitle();
}
}
// rest of AdListener implementation omitted
});
nativeAd.loadAd();
Before displaying the ad, call registerViewForInteraction(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.Rating
Rating info.
|
Constructor and Description |
---|
NativeAd(Context context,
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,
ImageView imageView)
Downloads the given Image and displays it in the given ImageView.
|
String |
getAdBody()
Gets the body, usually a longer description of the ad.
|
String |
getAdCallToAction()
Gets the call to action phrase.
|
NativeAd.Image |
getAdCoverImage()
Gets the cover image creative.
|
NativeAd.Image |
getAdIcon()
Gets the icon creative.
|
String |
getAdSocialContext()
Gets the social context.
|
NativeAd.Rating |
getAdStarRating()
Gets the star rating.
|
String |
getAdTitle()
Gets the title.
|
boolean |
isAdLoaded()
Gets whether an ad is loaded and ready to show.
|
void |
loadAd()
Loads an ad.
|
void |
registerViewForInteraction(View view)
Registers the given view as the container for this NativeAd to handle impressions and
clicks.
|
void |
registerViewForInteraction(View view,
List<View> clickableViews)
Registers the given view as the container for this NativeAd to handle impressions and
clicks.
|
void |
setAdListener(AdListener adListener)
Sets an AdListener to be notified on events happened in control lifecycle.
|
void |
setImpressionListener(ImpressionListener impListener)
Sets an ImpressionListener to be notified of impression events in ad control lifecycle.
|
void |
unregisterView() |
public void setAdListener(AdListener adListener)
adListener
- the listenerpublic void setImpressionListener(ImpressionListener impListener)
impListener
- the listenerpublic 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 destroy()
Ad
This method should be called when the hosting activity of the ad control is destroyed.
public boolean isAdLoaded()
public NativeAd.Image getAdIcon()
public NativeAd.Image getAdCoverImage()
public String getAdTitle()
public String getAdBody()
public String getAdCallToAction()
public String getAdSocialContext()
public NativeAd.Rating getAdStarRating()
public static void downloadAndDisplayImage(NativeAd.Image image, ImageView imageView)
image
- image to be downloadedimageView
- view to show the downloaded imagepublic void registerViewForInteraction(View view)
view
- the View containing this NativeAd for displaypublic void registerViewForInteraction(View view, List<View> clickableViews)
view
- the View containing this NativeAd for displayclickableViews
- a list of all view elements that should handle taps on this unitpublic void unregisterView()