- Custom Events in Admob Mediattion adding unsupported Ad Networks
- public class CustomEvent implements CustomEventBanner, AdListener{
- private CustomEventBannerListener bannerListener;
- private AdView adView;
- @Override
- public void requestBannerAd(final CustomEventBannerListener listener,
- final Activity activity,
- String label,
- String serverParameter,
- AdSize adSize,
- MediationAdRequest mediationAdRequest) {
- // Keep the custom event listener for use later.
- this.bannerListener = listener;
- // Determine the best ad format to use given the adSize. If the adSize
- // isn't appropriate for any format, an ad will not fill.
- AdSize bestAdSize = adSize = adSize.findBestSize(
- AdSize.BANNER,
- AdSize.IAB_BANNER,
- AdSize.IAB_LEADERBOARD,
- AdSize.IAB_MRECT,
- AdSize.IAB_WIDE_SKYSCRAPER);
- if (bestAdSize == null) {
- listener.onFailedToReceiveAd();
- return;
- }
- // Initialize an AdView with the bestAdSize and the publisher ID.
- // The publisher ID is the server parameter that you gave when creating
- // the custom event.
- this.adView = new AdView(activity, bestAdSize, serverParameter);
- // Set the listener to register for events.
- this.adView.setAdListener(this);
- // Generate an ad request using custom targeting values provided in the
- // MediationAdRequest.
- AdRequest adRequest = new AdRequest()
- .setBirthday(mediationAdRequest.getBirthday())
- .setGender(mediationAdRequest.getGender())
- .setKeywords(mediationAdRequest.getKeywords())
- .setLocation(mediationAdRequest.getLocation());
- if (mediationAdRequest.isTesting()) {
- adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
- }
- // Load the ad with the ad request.
- this.adView.loadAd(adRequest);
- }
- @Override
- public void onReceiveAd(Ad ad) {
- this.bannerListener.onReceivedAd(this.adView);
- }
- @Override
- public void onFailedToReceiveAd(Ad ad, ErrorCode errorCode) {
- this.bannerListener.onFailedToReceiveAd();
- }
- @Override
- public void onPresentScreen(Ad ad) {
- this.bannerListener.onClick();
- this.bannerListener.onPresentScreen();
- }
- @Override
- public void onDismissScreen(Ad ad) {
- this.bannerListener.onDismissScreen();
- }
- @Override
- public void onLeaveApplication(Ad ad) {
- this.bannerListener.onLeaveApplication();
- }
- }