[EDIT]:
Scroll down this thread to the approved and correct version of the Geystripe CustomEvent [EDIT]
I want to add a custom network (Greystripe) to my Admob mediation network.
I understand the following:
[ol]
[li]I need to add the network in the Admob dahsboard by supplying the fully qualified class name of my CustomEvent class, a label and optional a String parameter
[/li][li]The optional paramater is passed to my Custom Event class as serverParameter
[/li][li]I need to create a CustomEvent class, which is instantiated by Admob when a request is received.
[/li][/ol]
I found an example of such a CustomEvent class on stackoverflow.com http://stackoverflow.com/questions/11667285/custom-events-in-admob-mediattion-adding-unsupported-ad-networks
This is the class:
public class CustomEvent implements CustomEventBanner, AdListener{
private CustomEventBannerListener bannerListener;
private AdView adView;
private static final String TAG = "CustomEvent";
@Override
// interface CustomEventBanner
public void requestBannerAd(final CustomEventBannerListener listener,
final Activity activity,
String label,
String serverParameter,
AdSize adSize,
MediationAdRequest mediationAdRequest) {
Log.d(TAG, "requestBannerAd(); serverParameter: " + serverParameter);
// 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
// interface AdListener
public void onReceiveAd(Ad ad) {
Log.d(TAG, "onReceiveAd()");
this.bannerListener.onReceivedAd(this.adView);
}
@Override
// interface AdListener
public void onFailedToReceiveAd(Ad ad, ErrorCode errorCode) {
Log.d(TAG, "onFailedToReceiveAd(); Errorcode: " + errorCode.toString());
this.bannerListener.onFailedToReceiveAd();
}
@Override
// interface AdListener
public void onPresentScreen(Ad ad) {
Log.d(TAG, "onPresentScreen()");
this.bannerListener.onClick();
this.bannerListener.onPresentScreen();
}
@Override
// interface AdListener
public void onDismissScreen(Ad ad) {
Log.d(TAG, "onDismissScreen()");
this.bannerListener.onDismissScreen();
}
@Override
// interface AdListener
public void onLeaveApplication(Ad ad) {
Log.d(TAG, "onLeaveApplication()");
this.bannerListener.onLeaveApplication();
}
}
I believe, I have to modify the method requestBannerAd().
But I dont understand, how I can obtain a reference to my ad container (A LinearLayout tag in my activities’ xml).
Then I check if I receive the ad inside the requestBannerAd() method, add the ad, and call onReceiveAd() .
If I don’t receive one, I call onFailedToReceiveAd() respectively. :huh:
Can anybody enlight me and point me in the right direction?