Millennial Media Android Ad SDK Public Documentation  6.6.1
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
NativeAd Class Reference

Inherits AdPlacement.

Classes

enum  ComponentName
 
class  NativeAdMetadata
 
class  NativeErrorStatus
 
interface  NativeListener
 

Public Member Functions

void load (final Context context, NativeAdMetadata nativeAdMetadata) throws MMException
 
CreativeInfo getCreativeInfo ()
 
void setListener (NativeListener nativeListener)
 
boolean isReady ()
 
boolean hasExpired ()
 
void invokeDefaultAction ()
 
void fireImpression () throws MMException
 
String getNativeType ()
 
TextView getTitle ()
 
TextView getTitle (int instanceId)
 
TextView getBody ()
 
TextView getBody (int instanceId)
 
ImageView getIconImage ()
 
ImageView getIconImage (int instanceId)
 
ImageView getMainImage ()
 
ImageView getMainImage (int instanceId)
 
Button getCallToActionButton ()
 
Button getCallToActionButton (int instanceId)
 
TextView getRating ()
 
TextView getRating (int instanceId)
 
TextView getDisclaimer ()
 
TextView getDisclaimer (int instanceId)
 
void updateLayout (View layout) throws MMException
 
View inflateLayout (Context context, int[] layoutIds) throws MMException
 
synchronized void destroy ()
 
boolean isDestroyed ()
 

Static Public Member Functions

static NativeAd createInstance (String placementId, String nativeType) throws MMException
 
static NativeAd createInstance (String placementId, String[] nativeTypes) throws MMException
 

Static Public Attributes

static final String NATIVE_TYPE_INLINE = "inline"
 

Detailed Description

NativeAd is the ad placement that can be used for displaying ad content natively in any app. Each NativeAd must have a unique placementId and an adType.

Once ad content has been loaded using load, the callback NativeListener.onLoaded will fire. After the load succeeds the ad content can be accessed through the various NativeAd getters.

Member Function Documentation

◆ createInstance() [1/2]

static NativeAd createInstance ( String  placementId,
String  nativeType 
) throws MMException
static

Constructs a NativeAd instance with a unique placementId and a specific ad type.

Parameters
placementIdidentifier of the placement that is used by the server for selecting ad content
nativeTyperequested native type
Returns
Newly created NativeAd instance or null if there was an error
Exceptions
MMExceptionif nativeType is invalid or the SDK is not initialized

◆ createInstance() [2/2]

static NativeAd createInstance ( String  placementId,
String []  nativeTypes 
) throws MMException
static

Constructs a NativeAd instance with a unique placementId and an array of specific ad types.

Parameters
placementIdidentifier of the placement that is used by the server for selecting ad content
nativeTypesarray of requested native types
Returns
Newly created NativeAd instance or null if there was an error
Exceptions
MMExceptionif nativeTypes are invalid or the SDK is not initialized

◆ destroy()

synchronized void destroy ( )
inherited

Destroys the internal components of the ad. If the ad is in a loading state the destroy will happen after the loading completes.

After the ad has been destroyed it can no longer be used to make requests and all public API methods called will fail with a message outputted to the logs. Remove all references to this placement and create a new placement to make a new ad request.

◆ fireImpression()

void fireImpression ( ) throws MMException

Signals that the native ad container view has been presented on screen and is viewable.
Some components are required to be shown before tracking the impression. Failure to do so will throw a MMException

Exceptions
MMExceptionthrown when one or more components have not been accessed that are required to be shown before firing the impression tracker

◆ getBody() [1/2]

TextView getBody ( )

Retrieves the body text view for the ad.

Returns
The body text view for the ad, or null if there is no text available

◆ getBody() [2/2]

TextView getBody ( int  instanceId)

Retrieves the body text view for the ad for a given instanceId.

Parameters
instanceIdrepresents which body instance to retrieve starting from 1
Returns
The body text view for the ad, or null if there is no text available

◆ getCallToActionButton() [1/2]

Button getCallToActionButton ( )

Retrieves the button for the 'call to action' for the ad.

Returns
The 'call to action' button for the ad, or null if there is no button available

◆ getCallToActionButton() [2/2]

Button getCallToActionButton ( int  instanceId)

Retrieves the button for the 'call to action' for the ad for a given instanceId.

Parameters
instanceIdrepresents which call to action instance to retrieve starting from 1
Returns
The 'call to action' button for the ad, or null if there is no button available

◆ getCreativeInfo()

CreativeInfo getCreativeInfo ( )

Retrieves a CreativeInfo object, containing the creativeId and demandSource.

Returns
the CreativeInfo object.

◆ getDisclaimer() [1/2]

TextView getDisclaimer ( )

Retrieves the disclaimer text view for the ad.

Returns
The disclaimer text view for the ad, or null if there is no text available

◆ getDisclaimer() [2/2]

TextView getDisclaimer ( int  instanceId)

Retrieves the disclaimer text view for the ad for a given instanceId.

Parameters
instanceIdrepresents which disclaimer instance to retrieve starting from 1
Returns
The disclaimer text view for the ad, or null if there is no text available

◆ getIconImage() [1/2]

ImageView getIconImage ( )

Retrieves the icon image view for the ad.

Returns
The icon image view for the ad, or null if there is no image available

◆ getIconImage() [2/2]

ImageView getIconImage ( int  instanceId)

Retrieves the icon image view for the ad for a given instanceId.

Parameters
instanceIdrepresents which icon image instance to retrieve starting from 1
Returns
The icon image view for the ad, or null if there is no image available

◆ getMainImage() [1/2]

ImageView getMainImage ( )

Retrieves the main image view for the ad.

Returns
The main image view for the ad, or null if there is no image available

◆ getMainImage() [2/2]

ImageView getMainImage ( int  instanceId)

Retrieves the main image view for the ad for a given instanceId.

Parameters
instanceIdrepresents which main image instance to retrieve starting from 1
Returns
The main image view for the ad, or null if there is no image available

◆ getNativeType()

String getNativeType ( )

Retrieves the type of the NativeAd.

Returns
The type of the NativeAd, for example "inline"

◆ getRating() [1/2]

TextView getRating ( )

Retrieves the rating text view for the ad.

Returns
The rating text view for the ad, or null if there is no rating available

◆ getRating() [2/2]

TextView getRating ( int  instanceId)

Retrieves the rating text view for the ad for a given instanceId.

Parameters
instanceIdrepresents which rating instance to retrieve starting from 1
Returns
The rating text view for the ad, or null if there is no rating available

◆ getTitle() [1/2]

TextView getTitle ( )

Retrieves the title text view for the ad.

Returns
The title text view for the ad, or null if there is no text available

◆ getTitle() [2/2]

TextView getTitle ( int  instanceId)

Retrieves the title text view for the ad for a given instanceId.

Parameters
instanceIdrepresents which title instance to retrieve starting from 1
Returns
The title text view for the ad, or null if there is no text available

◆ hasExpired()

boolean hasExpired ( )

Determines if the loaded ad content has expired and must be reloaded.

Returns
true if expired, false otherwise

◆ inflateLayout()

View inflateLayout ( Context  context,
int []  layoutIds 
) throws MMException

This method will select the best possible layout from the set of layouts to fill from this NativeAd. The layout must support the minimum publisher required components.

Parameters
contextthe Context that will be used to obtain the LayoutInflater. Typically your Activity.
layoutIdsthe resource IDs for the layouts to be evaluated and inflated. They should be in priority order.
Returns
the selected layout per the publisher required fields and fill or null if none of the layouts met the publisher required fields
Exceptions
com.millennialmedia.MMExceptionthrown if there is an error populating the Views in the layout. Typically caused by type mismatches. For example the icon requires an ImageView but the layout provided a TextView.

◆ invokeDefaultAction()

void invokeDefaultAction ( )

Performs the default action for the ad. This method should be called when the ad is clicked.

◆ isDestroyed()

boolean isDestroyed ( )
inherited

Determines if the ad placement has been destroyed.

Returns
true if destroyed, false otherwise

◆ isReady()

boolean isReady ( )

Determines if a NativeAd is ready to be shown.

Returns
true if ready, false otherwise

◆ load()

void load ( final Context  context,
NativeAdMetadata  nativeAdMetadata 
) throws MMException

Loads new ad content for this placement. If the load succeeds the NativeListener.onLoaded callback will be invoked.
If the load fails the NativeListener.onLoadFailed callback will be invoked.

Parameters
contextthe context that will be used for loading new NativeAd content
nativeAdMetadatathe NativeAdMetadata object to be used in the request
Exceptions
MMExceptionthrown if context is not a valid Context

◆ setListener()

void setListener ( NativeListener  nativeListener)

Sets the listener on the NativeAd.

Parameters
nativeListenerthe NativeListener to be set

◆ updateLayout()

void updateLayout ( View  layout) throws MMException

Applies the ad content of this NativeAd instance to the layout provided. The layout must contain at least the minimum publisher required views for the given native ad type.

Parameters
layoutthe layout to update
Exceptions
MMExceptionthrown if there is a type mismatch with any of the Views in the layout. For example icon image expects an ImageView and the layout provided a TextView.

Member Data Documentation

◆ NATIVE_TYPE_INLINE

final String NATIVE_TYPE_INLINE = "inline"
static

Inline native type