Docy

Banners

1. Add the AdView

The first step toward displaying a banner is to place Yodo1MasBannerAdView in the layout for the Activity or Fragment in which you’d like to display it. The easiest way to do this is to add one to the corresponding XML layout file. Here’s an example that shows an activity’s Yodo1MasBannerAdView:

				
					<com.yodo1.mas.banner.Yodo1MasBannerAdView 
		xmlns:masads="http://schemas.android.com/apk/res-auto"
		android:id="@+id/yodo1_mas_banner"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_gravity="center_horizontal|top"
		masads:adSize="Banner" />
				
			

Note the following required attributes:

  • masads:adSize – Set this to the ad size you’d like to use.

You can alternatively create Yodo1MasBannerAdView programmatically:

Yodo1MasBannerAdView bannerAdView = new
Yodo1MasBannerAdView(this);
bannerAdView.setAdSize(Yodo1MasBannerAdSize.Banner);
// TODO: Add bannerAdView to your view hierarchy.
val bannerAdView = Yodo1MasBannerAdView(this)
bannerAdView.setAdSize(Yodo1MasBannerAdSize.Banner)
// TODO: Add bannerAdView to your view hierarchy.

Banner sizes

Size in dp Description Availability AdSize Constant
320×50 Banner Phones and Tablets Banner
320×100 Large Banner Phones and Tablets Large Banner
300×250 IAB Medium Rectangle Phones and Tablets IAB Medium Rectangle
Full-screen width x
Adaptive height
Adaptive Banner Phones and Tablets Adaptive Banner
Screen width x 32/50/90 Smart Banner Phones and Tablets Smart Banner

2. Load an ad

Once the Yodo1MasBannerAdView is in place, the next step is to load an ad. That’s done with the loadAd() method in the Yodo1MasBannerAdView class.

Here’s an example that shows how to load an ad in the onCreate() method of an Activity:

AndroidBannerInte- LoadanAd

package...
import...
import com.yodo1.mas.Yodo1Mas;
import com.yodo1.mas.banner.Yodo1MasBannerAdView;
public class MainActivity extends AppCompatActivity { 
private Yodo1MasBannerAdView bannerAdView; 
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Yodo1Mas.getInstance().init(this, "YourAppKey", new Yodo1Mas.InitListener() {
@Override public void onMasInitSuccessful() { }
@Override public void onMasInitFailed(@NonNull Yodo1MasError error) { } });
bannerAdView = findViewById(R.id.yodo1_mas_banner);
bannerAdView.loadAd(); } }
package...
import...
import com.yodo1.mas.Yodo1Mas;
import com.yodo1.mas.banner.Yodo1MasBannerAdView;
class MainActivity : AppCompatActivity() {
lateinit var bannerAdView : Yodo1MasBannerAdView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) setContentView(R.layout.activity_main)
Yodo1Mas.getInstance().init(this, "YourAppKey", object : Yodo1Mas.InitListener {
override fun onMasInitSuccessful() {
Toast.makeText(this@MainActivity, 
"[Yodo1 Mas] Successful initialization", Toast.LENGTH_SHORT).show() }
override fun onMasInitFailed(error: Yodo1MasError) {
Toast.makeText(this@MainActivity, error.message, Toast.LENGTH_SHORT).show() } })
bannerAdView = findViewById(R.id.yodo1_mas_banner) bannerAdView.loadAd() } }

That’s it! Your app is now ready to display banner ads.

3. Ad events

To further customize the behavior of your ad, you can hook onto a number of events in the ad’s lifecycle: loading, opening, closing, and so on. You can listen for these events through the Yodo1MasBannerAdListener class.

package...
import...
import com.yodo1.mas.Yodo1Mas;
import com.yodo1.mas.banner.Yodo1MasBannerAdListener;
import com.yodo1.mas.banner.Yodo1MasBannerAdView;
public class MainActivity extends AppCompatActivity {
private Yodo1MasBannerAdView bannerAdView; 
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Yodo1Mas.getInstance().init(this, "YourAppKey", new Yodo1Mas.InitListener() {
@Override public void onMasInitSuccessful() { }
@Override public void onMasInitFailed(@NonNull Yodo1MasError error) { } });
bannerAdView = findViewById(R.id.yodo1_mas_banner);
bannerAdView.setAdListener(new Yodo1MasBannerAdListener() {
@Override public void onBannerAdLoaded(Yodo1MasBannerAdView bannerAdView) {
// Code to be executed when an ad finishes loading.
}
@Override
public void onBannerAdFailedToLoad(Yodo1MasBannerAdView bannerAdView, @NonNull Yodo1MasError error) {
// Code to be executed when an ad request fails.
}
@Override public void onBannerAdOpened(Yodo1MasBannerAdView bannerAdView) {
// Code to be executed when an ad opens an overlay that covers the screen.
}
@Override
public void onBannerAdFailedToOpen(Yodo1MasBannerAdView bannerAdView, @NonNull Yodo1MasError error) {
// Code to be executed when an ad open fails.
}
@Override
public void onBannerAdClosed(Yodo1MasBannerAdView bannerAdView) {
// Code to be executed when the user is about to return to the app after tapping on an ad. 
} }); bannerAdView.loadAd(); } }
package...
import...
import com.yodo1.mas.Yodo1Mas; import com.yodo1.mas.banner.Yodo1MasBannerAdListener;
import com.yodo1.mas.banner.Yodo1MasBannerAdView; class MainActivity :
AppCompatActivity() {
lateinit var bannerAdView : Yodo1MasBannerAdView 
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) 
Yodo1Mas.getInstance().init(this, "YourAppKey", object : Yodo1Mas.InitListener {
override fun onMasInitSuccessful() {
Toast.makeText(this@MainActivity, "[Yodo1 Mas] Successful initialization", Toast.LENGTH_SHORT).show() }
override fun onMasInitFailed(error: Yodo1MasError) {
Toast.makeText(this@MainActivity, error.message, Toast.LENGTH_SHORT).show() } })
bannerAdView = findViewById(R.id.yodo1_mas_banner) bannerAdView.setAdListener(object : Yodo1MasBannerAdListener {
override fun onBannerAdLoaded(bannerAdView: Yodo1MasBannerAdView?) {
// Code to be executed when an ad finishes loading.
}
override fun onBannerAdFailedToLoad( bannerAdView: Yodo1MasBannerAdView?, error: Yodo1MasError ) {
// Code to be executed when an ad request fails.
}
override fun onBannerAdOpened(bannerAdView: Yodo1MasBannerAdView?) {
// Code to be executed when an ad opens an overlay that covers the screen.
}
override fun onBannerAdFailedToOpen( bannerAdView: Yodo1MasBannerAdView?, error: Yodo1MasError ) {
// Code to be executed when an ad open fails.
}
override fun onBannerAdClosed(bannerAdView: Yodo1MasBannerAdView?) {
// Code to be executed when the user is about to return to the app after tapping on an ad. } }) bannerAdView.loadAd() } }

4. Video tutorial

CONTENTS