Millennial Media Android Ad SDK Public Documentation  6.3.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
 
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
 

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

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
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
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
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
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
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
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
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
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
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
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
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
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
String getNativeType ( )

Retrieves the type of the NativeAd.

Returns
The type of the NativeAd, for example "inline"
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
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
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
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
boolean hasExpired ( )

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

Returns
true if expired, false otherwise
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.
void invokeDefaultAction ( )

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

boolean isReady ( )

Determines if a NativeAd is ready to be shown.

Returns
true if ready, false otherwise
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
void setListener ( NativeListener  nativeListener)

Sets the listener on the NativeAd.

Parameters
nativeListenerthe NativeListener to be set
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

final String NATIVE_TYPE_INLINE = "inline"
static

Inline native type