Android SDK Usage

Important: When building and testing your apps, make sure you use test ads rather than production ads. Failure to do so can lead to suspension of your account. Please see the Optional Parameters section for more info on toggling the test ads.

Banner Ads

Once the initialization of the SDK is complete, you can get and load banner ads from the EMAManager instance automatically by using the following method:

EMAManager.getInstance().loadBannerAd(this, zoneId, bannerContainer, this)

If you don't want to load banner ads automatically:

val bannerManager = EMAManager.getInstance().loadBannerAd(this,zoneId, bannerContainer, this)
bannerManager.loadBanner()
...
override fun DFPBannerStatusChanged(manager: DFPBannerManager) {
super.DFPBannerStatusChanged(manager)
AdStatus.READY -> {
bannerContainer.addView(bannerManager.banner)
}
}

this: Activity or Fragment

zoneId: Banner id that will be loaded in the view.

bannerContainer: ViewGroup container that banner ad is loaded.

this(Optional): AdStatusListener to be informed by the banner load status.

adConfiguration: If you don't want to load ads automatically, create AdConfiguration object and send as false. ex: (AdConfiguration(false))

customParameters: You can pass custom key-value pairs to target Google Ad Manager campaigns.

keywords: If you are using keywords for targeting, send your parameters as string value.

Note: You should callloadBannerAdmethod in the onCreate().

You can set a manager's AdStatusListener. An AdStatusListener is used for getting callbacks during the ads' lifecycles. You can send as a fourth parameter for the listener.Depending on the callbacks, you may either display the ad to the user or skip it entirely.

EMAManager.getInstance().loadBannerAd(this, zoneId, bannerContainer, this)// AdStatusListener

If you implement AdStatusListener, Once the EMAManager.getInstance().loadBannerAd method is called, one of these below three will happen, otherwise SDK will manage the lifecycle of bannerAd.

  • bannerStatusChanged will be called with status of bannerManager set to AdStatus.READY.
  • bannerStatusChanged will be called with status of bannerManager set to AdStatus.FAILED.
  • If ads are disabled or the user in an unfinished ad session, then bannerManager.loadBannerAd call will be ignored and nothing will happen.

Note: In the full example code you will see sample zoneId 123456. You will be given your actual zoneIds by us, and you will have to replace these sample ids with actual zone ids.

Full Example

public class MyActivity extends AppCompatActivity {
private RelativeLayout relativeLayoutForBanner;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
relativeLayoutForBanner = findViewById(relativeLayoutForBanner);
EMAManager.getInstance().loadBannerAd(this,123456, relativeLayoutForBanner);
}

Native Ads

Once the initialization of the SDK is complete, you can get and load native ads from the EMAManager instance by using the following method:

EMAManager.getInstance().loadNativeAd(this, zoneId, emaNativeDisplayAdapter)

this: Activity or Fragment

zoneId: Native ad id that will be loaded.

EMANativeAdDisplayAdapter: Adapter that takes viewGroup as a parameter that native ad will be loaded. Responsible for loading ad that you configure in displayUnifiedAd method and adding to container.

Note: You should callloadNativeAdmethod in the onCreate().

If you implement AdStatusListener, Once the EMAManager.getInstance().loadNativeAd method is called, one of these below three will happen, otherwise SDK will manage the lifecycle of bannerAd.

  • nativeAdStatusChanged will be called with status of bannerManager set to AdStatus.READY.
  • nativeAdStatusChanged will be called with status of bannerManager set to AdStatus.FAILED.

Note: In the full example code you will see sample zoneId 123456. You will be given your actual zoneIds by us, and you will have to replace these sample ids with actual zone ids.

Full Example

public class MyActivity extends AppCompatActivity {
private RelativeLayout relativeLayoutForBanner;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
relativeLayoutForNativeAd = findViewById(relativeLayoutForBanner);
EMAManager.getInstance().loadNativeAd(this, 12345, relativeLayoutForNativeAd, new EMANativeAdDisplayAdapter(relativeLayoutForNativeAd) {
@NotNull @Override
public NativeAdView displayUnifiedAd(@NonNull NativeAd unifiedNativeAd) {
LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
NativeAdView adView = ((NativeAdView)inflater.inflate(R.layout.layout_native_banner, native_ad_view, false);
TextView headlineView = adView.findViewById<TextView>(R.id.primary)
TextView secondary = adView.findViewById<TextView>(R.id.primary)
headlineView.setText( unifiedNativeAd.getHeadline()))
secondary.setText(unifiedNativeAd.getBody())
adView.headlineView = headlineView;
return adView;
}
});
}

App Open Ads

App open ads are specialized ad format for publishers who wants to monetize their app on load screens.

Full Example

public class SplashActivity extends AppCompatActivity implements AppViewParserListener {
@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.activity_main);
EMAManager.getInstance().init(this,"test_android", "1");
EMAManager.getInstance().setAppViewParserListener(this)
}
@Override
public void onSuccessAppViewParse() {
AppOpenAdManager appOpenAdManager = EMAManager.getInstance().getAppOpenManager(this);
appOpenAdManager.setAppOpenEventListener(new AppOpenEventListener() {
@Override
public void onShowAdComplete() {
AppOpenEventListener.super.onShowAdComplete();
appOpenAdManager.setAppOpenEventListener(null);
EMAManager.getInstance().setAppViewParserListener(null);
startMainActivity();
}
@Override
public void onAdLoaded() {
AppOpenEventListener.super.onAdLoaded();
appOpenAdManager.showAdIfAvailable(this@SplashScreen);
}
@Override
public void onAdFailedToLoad() {
AppOpenEventListener.super.onAdFailedToLoad();
startMainActivity();
}
});
}
@Override
public void onFailedAppViewParse() {
}
private void startMainActivity() {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
}

By setting AppViewParser listener, you can know wheter ads is ready to display or not. After onSuccessAppViewParse is triggered, you can show App Open ad via EMAManager. All the operations is handled by the SDK.

Note: AppView request is sent by every 4 minute. Therefore, you should set appview parser listener to null to avoid show app open ad again.

Sticky Banner Ads

Sticky banner ads are usually displayed at the bottom of the screen or above the tab bar. These banner ads are always visible to the user.

Full Example

public class MyActivity extends AppCompatActivity {
RelativeLayout relativeLayoutForStickyBanner;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
relativeLayoutForStickyBanner = findViewById(R.id.relativeLayoutStickyBanner)
EMAManager.instance.loadBannerAd(this,123456, relativeLayoutForStickyBanner)
}
}

By setting StickyBannerManager's listener you can listen to the status events of sticky banner ads. These events are:

  • AdStatus.READY sticky banner is ready for display.
  • AdStatus.FAILED sticky banner is failed to load an ad.
  • AdStatus.PRESENT sticky banner is recorded as impression.
  • AdStatus.WILL_LEAVE sticky banner is redirecting user to a URL.

Interstitial Ad

Interstitial ads are full-screen ads that cover the interface of their host app.

Full Example

public class MyActivity extends AppCompatActivity implements AdStatusListener {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
InterstitialDisplayManager.getInstance().setListener(this);
InterstitialDisplayManager.getInstance().loadInterstitial();
}
@Override
public void DFPInterstitialStatusChanged(@NonNull DFPInterstitialManager manager) {
AdStatusListener.super.DFPInterstitialStatusChanged(manager);
if(manager.getStatus().equals(AdStatus.READY)) {
InterstitialDisplayManager.getInstance().showInterstitial();
}
}
}

By setting InterstitialDisplayManager's listener you can listen to the status events of interstitial ads. These events are:

  • AdStatus.READY: interstitial is ready for display.
  • AdStatus.FAILED: insterstitial is failed to load an ad.
  • AdStatus.PRESENT: interstitial is displayed and is on screen.
  • AdStatus.WILL_LEAVE: interstitial is redirecting user to a URL.
  • AdStatus.USED: interstitial is dismissed and needs reloading for another display

Rewarded Ads

Rewarded ads are the ads where users have the option of interacting with in exchange for in-app rewards.

Before you load and show a rewarded ad you must set EMASettings.instance.activity = currentActivity and the listener for the status of ad RewardedAdDisplayManager.instance.listener = this.

Full Example

public class MyActivity extends AppCompatActivity implements AdStatusListener {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
RewardedAdDisplayManager.getInstance().loadRewarded()
}
@Override public void rewardedStatusChanged(@NotNull RewardedAdManager manager) {
if(manager.getStatus().equals(AdStatus.READY)) {
RewardedAdDisplayManager.getInstance().showRewarded();
}
}
}

By setting RewardedAdDisplayManager's listener you can listen to the status events of rewarded ads. These events are:

  • AdStatus.READY: rewarded is ready for display.
  • AdStatus.FAILED: rewarded ad is failed to load.
  • AdStatus.OPENED: rewarded ad is started to play and is on screen.
  • AdStatus.REWARDED: user complete playing and earns reward.
  • AdStatus.CLOSED: rewarded ad is closed either by user or complete playing.

IMA Preroll Ads

IMA preroll ads can be displayed on ExoPlayer instances.

In order to be able to display a preroll ad, first you must request ads from the SDK:

...
// After setting the video request ads
IMADisplayManager.getInstance().setListener(this) // AdStatusListener
IMADisplayManager.getInstance().requestAd(["YOUR_AD_CATEOGRY"], playerContainer, exoPlayer)

By setting IMADisplayManager listener you can listen to the status events of preroll ads. These events are:

AdStatus.READY: preroll ad is ready for display. AdStatus.FAILED: preroll ad is either failed to play or failed to load. AdStatus.ACTIVE: preroll ad is being played. AdStatus.PAUSED: preroll ad is paused by the user.