public class NativeAd
extends java.lang.Object
View that
displays a native ad, tracking impressions and clicks for it.
Using MoPubStreamAdPlacer, you can automatically have NativeAds rendered into
Views and inserted into your app's content stream without manipulating this class
directly.
In general you should get instances of NativeAd from MoPubNative instances in its
MoPubNative.onAdLoad(AdResponse) callback
and should not construct them directly.
When you have a NativeAd instance and wish to show a view you should:
1. Call createAdView(Context, ViewGroup) to inflate a View that can show this ad.
2. Call renderAdView(View) with a compatible View to render the ad data into the view.
3. Just before the ad is shown to the user, call prepare(View).
4. When the ad view is no longer shown to the user, call clear(View). You can later
call prepare(View) again if the ad will be shown to users.
5. When the ad will never be shown again, call destroy().| Modifier and Type | Class and Description |
|---|---|
static interface |
NativeAd.MoPubNativeEventListener
Listen for MoPub specific click and impression events
|
| Constructor and Description |
|---|
NativeAd(android.content.Context context,
java.lang.String moPubImpressionTrackerUrl,
java.lang.String moPubClickTrackerUrl,
java.lang.String adUnitId,
BaseNativeAd baseNativeAd,
MoPubAdRenderer moPubAdRenderer) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear(android.view.View view)
Clears
NativeAd state associated with this View. |
android.view.View |
createAdView(android.content.Context context,
android.view.ViewGroup parent)
Renders the ad view.
|
void |
destroy()
Cleans up all
NativeAd state. |
java.lang.String |
getAdUnitId() |
BaseNativeAd |
getBaseNativeAd()
Returns the
BaseNativeAd object for this NativeAd. |
MoPubAdRenderer |
getMoPubAdRenderer() |
boolean |
isDestroyed() |
void |
prepare(android.view.View view)
Prepares the
NativeAd to be seen on screen. |
void |
renderAdView(android.view.View view) |
void |
setMoPubNativeEventListener(NativeAd.MoPubNativeEventListener moPubNativeEventListener) |
java.lang.String |
toString() |
public NativeAd(android.content.Context context,
java.lang.String moPubImpressionTrackerUrl,
java.lang.String moPubClickTrackerUrl,
java.lang.String adUnitId,
BaseNativeAd baseNativeAd,
MoPubAdRenderer moPubAdRenderer)
public java.lang.String toString()
toString in class java.lang.Objectpublic void setMoPubNativeEventListener(NativeAd.MoPubNativeEventListener moPubNativeEventListener)
public java.lang.String getAdUnitId()
public boolean isDestroyed()
public BaseNativeAd getBaseNativeAd()
BaseNativeAd object for this NativeAd. This object is created by
a CustomEventNative subclass after a successful ad request and is specific to the ad
source. If it comes from the MoPub Exchange or is a directly-served ad it will be of the type
MoPubCustomEventNative.MoPubStaticNativeAd or MoPubVideoNativeAd. If it is returned by a mediated ad
network it may have another type.public android.view.View createAdView(android.content.Context context,
android.view.ViewGroup parent)
context - The context, preferably the Activity.parent - An optional parent.public void renderAdView(android.view.View view)
public MoPubAdRenderer getMoPubAdRenderer()
public void prepare(android.view.View view)
NativeAd to be seen on screen. You should call this method after calling
renderAdView(View) with the same View and before the ad is shown on-screen.
This method is commonly used to initialize impression tracking and other state associated
with the View.public void clear(android.view.View view)
public void destroy()