Banner Integration

Banner ads usually appears at the top or bottom of your app’s screen. Adding one to your app takes just a few lines of code.

Prerequisites

Before integrating banner ads in your app, you’ll need to go through the steps in our Getting Started Guide to integrate the SDK into your project.

In order to display this ad, you need to create a "Mobile Banner" or "Expandable" AdUnit. You can create a new one here.

Choosing mobile adunit dimension

Define a slot for your banner ad in your layout XML

The Instal SDK provides a custom View subclass, InstalAdView, that handles requesting and loading ads. InstalAdView can be used for both standard and expandable banner, you can choose the type in the adunit configuration page.

Add this XML block to your Activity’s or Fragment’s layout. The expected dimensions for a banner are match_parent for the the width and wrap_content for the height; these should not be modified.

This is a simple with a text and the banner on the bottom:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

    <TextView
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <com.instal.mobileads.InstalAdView
        android:id="@+id/ad_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />
</RelativeLayout>

Load an ad into the banner slot

Next, in your Activity or Fragment code, declare an instance variable for your InstalAdView:

private InstalAdView adView;

In your Activity’s onCreate() or your Fragment’s onCreateView() method, set your Instal’s Ad Unit ID (you should already have created an ad unit on Instal’s site), then simply call loadAd() to fetch and display the ad:

adView = (InstalAdView) findViewById(R.id.ad_view);
adView.setAdUnitId("YOUR_ADUNIT_ID");
adView.loadAd();

When the hosting Activity or Fragment is destroyed, be sure to also destroy the InstalAdView by calling:

adView.destroy();

This is a complete example of an activity with a banner:

public class InstalAdActivity extends Activity {

    private InstalAdView adView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ad_view);
        adView = (InstalAdView) findViewById(R.id.ad_view);
        adView.setAdUnitId("1");
        adView.loadAd();
    }

    @Override protected void onDestroy() {
        super.onDestroy();
        adView.destroy();
    }
}