Inline Ads

Inline Ads, commonly referred to as “banners” or “rectangles”, are ad units that appear inline with other app content. Inline Ads are often found at the top or bottom of your screen while reading articles and searching through content. We recommend using Inline Ads on both smartphones and tablets in cases where the user is reading and/or interacting with content on the same screen for a period of time.

New in SDK 6, Lightbox Video!

With SDK 6, inline ad placements are capable of displaying a custom new ad unit called Lightbox. This ad unit takes advantage of native device functionality and gives publishers access to video demand historically only found with interstitial inventory. These new units are desirable to advertisers and provide a premium eCPM for publishers without any additional integration work. To ensure a placement is able to receive these ads, please reach out to your Millennial Media Account Manager or our support team.

Basic Integration

NOTE: Items in source like <YOUR_PLACEMENT_ID> must be replaced with your information.

1. Create the inline placement instance and set the listeners.
import com.millennialmedia.InlineAd;
import com.millennialmedia.MMException;

try {
	// NOTE: The ad container argument passed to the createInstance call should be the
	// view container that the ad content will be injected into.

    InlineAd inlineAd = InlineAd.createInstance(<YOUR_PLACEMENT_ID>, (ViewGroup) adContainer);

    inlineAd.setListener(new InlineAd.InlineListener() {
        @Override
        public void onRequestSucceeded(InlineAd inlineAd) {

            Log.i(TAG, "Inline Ad loaded.");
        }


        @Override
        public void onRequestFailed(InlineAd inlineAd, InlineAd.InlineErrorStatus errorStatus) {

            Log.i(TAG, errorStatus.toString());
        }


        @Override
        public void onClicked(InlineAd inlineAd) {

            Log.i(TAG, "Inline Ad clicked.");
        }


        @Override
        public void onResize(InlineAd inlineAd, int width, int height) {

            Log.i(TAG, "Inline Ad starting resize.");
        }


        @Override
        public void onResized(InlineAd inlineAd, int width, int height, boolean toOriginalSize) {

            Log.i(TAG, "Inline Ad resized.");
        }


        @Override
        public void onExpanded(InlineAd inlineAd) {

            Log.i(TAG, "Inline Ad expanded.");
        }


        @Override
        public void onCollapsed(InlineAd inlineAd) {

            Log.i(TAG, "Inline Ad collapsed.");
        }


        @Override
        public void onAdLeftApplication(InlineAd inlineAd) {

            Log.i(TAG, "Inline Ad left application.");
        }
    });

} catch (MMException e) {
    Log.e(TAG, "Error creating inline ad", e);
    // abort loading ad
}
2. Set the metadata and request the ad.
if (inlineAd != null) {
	// set a refresh rate of 30 seconds that will be applied after the first request
    // inlineAd.setRefreshInterval(30000);

    // The InlineAdMetadata instance is used to pass additional metadata to the server to
    // improve ad selection
    final InlineAd.InlineAdMetadata inlineAdMetadata = new InlineAd.InlineAdMetadata().
        setAdSize(InlineAd.AdSize.BANNER);

    inlineAd.request(inlineAdMetadata);
}

Additional Topics