Skip to content

Integrating Inline Ad

rprunskas edited this page May 31, 2022 · 8 revisions

Preparing view in xml

To add a banner view, insert a view with a path of com.adform.sdk.pub.views.AdInline. For the view to load an ad, you need to:

  • Define a master tag id by adding mastertag_id
  • Define banner size by adding ad_width and ad_height.

An example of view insert into a layout can be found below:

<com.adform.sdk.pub.views.AdInline
        android:id="@+id/custom_ad_view"
        mastertag_id="111111"
        ad_width="320"
        ad_height="50"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

Preparing view in code

For the SDK to work properly, a set of events ( destroy, return, pause ) should be provided from the Fragment/Activity. This can be done by doing these steps:

  1. Get created view instance

With Java:

private AdInline adInline;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_adinline);
    adInline = (AdInline) findViewById(R.id.custom_ad_view);
}
		

or Kotlin:

private lateinit var adInline: AdInline

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_adinline)
    adInline = findViewById(R.id.custom_ad_view)
}
  1. Report onDestroy, onResume,onPause events to the view

With Java:

@Override
protected void onResume() {
    super.onResume();
    adInline.onResume();
}

@Override
protected void onPause() {
    super.onPause();
    adInline.onPause();   
}

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

or Kotlin:

override fun onResume() {
    super.onResume()
    adInline.onResume()
}

override fun onPause() {
    super.onPause()
    adInline.onPause()
}

override fun onDestroy() {
    super.onDestroy()
    adInline.destroy()
}

Note that Fragment has slightly different methods than Activity, so if you are implementing code on Fragment, it should be public void onResume(), public void onPause(), public void onDestroy().

  1. When ad is ready, use loadAd() to start loading.

With Java:

adInline.loadAd();
		

or Kotlin:

adInline.loadAd()
		

Parameter setting

Note that some parameters can be set from both, xml layout and programmable code. If both are set, setting from programmable code overrides the xml one.

  • To set master tag you can use In XML:
<com.adform.sdk.pub.views.AdInline
    mastertag_id="111111"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

In Java code:

adInline.setMasterTagId(111111);

In Kotlin code:

adInline.masterTagId = 111111
  • To set ad size you can use

In XML:

<com.adform.sdk.pub.views.AdInline
    ad_height="50"
    ad_width="320"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
    

In Java code:

adInline.setAdSize(new AdSize(320, 50));
		

In Kotlin code:

adInline.adSize = AdSize(320, 50)
		
  • Smart size allows to display ad that fill the width of the screen. You could set smart size in this way:

In Java code

adInline.setAdSize(new SmartAdSize());
		

In Kotlin code

adInline.adSize = SmartAdSize()
		
  • In order to set multiple ad sizes you can use

In Java code:

adInline.setSupportedSizes(new AdSize(320, 50), new AdSize(300, 300), new AdSize(320, 160));
		

In Kotlin code:

adInline.setSupportedSizes(AdSize(320, 50), AdSize(300, 300), AdSize(320, 160))
		
  • If you want to support multiple ad sizes at the same placement without setting them, you could use additional dimensions feature.

In Java code:

adInline.setEnabledAdditionalDimensions(true);
		

In Kotlin code:

adInline.isEnabledAdditionalDimensions = true
		
  • To set ad tag you can use

In Java code:

adInline.setAdTag(yourAdTag);
		

In Kotlin code:

adInline.adTag = yourAdTag
		
Clone this wiki locally