public class AmazonBannerAd implements CustomEventBanner {
private static final String AMAZON_APPKEY = "1af21e56f2f64e12b1288283723db030";
private AdLayout mAdLayout;
private AdLayout getAdLayout(Context context) {
if (mAdLayout == null) {
mAdLayout = new AdLayout(context, com.amazon.device.ads.AdSize.SIZE_AUTO);
FrameLayout.LayoutParams mLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
mAdLayout.setLayoutParams(mLayoutParams);
}
return mAdLayout;
}
@Override
public void requestBannerAd(Context context,
final CustomEventBannerListener customEventBannerListener,
String s,
AdSize adSize,
MediationAdRequest mediationAdRequest,
Bundle bundle) {
// Sets up Amazon App Key
AdRegistration.setAppKey(AMAZON_APPKEY);
// Amazon Mobile Ads Code
AdRegistration.enableLogging(true);
AdRegistration.enableTesting(false);
// Initialize Amazon AdView
mAdLayout = new AdLayout(context);
final AdLayout adLayout = getAdLayout(context);
mAdLayout.setListener(new AmazonBannerAdListener(customEventBannerListener, adLayout));
AdTargetingOptions options = new AdTargetingOptions();
options.enableGeoLocation(true);
mAdLayout.loadAd(options);
}
@Override
public void onDestroy() {
if (mAdLayout != null) {
mAdLayout.destroy();
mAdLayout = null;
}
}
@Override
public void onPause() {
}
@Override
public void onResume() {
}
}
public class AmazonBannerAdListener implements AdListener {
private CustomEventBannerListener customEventBannerListener;
private AdLayout mAdLayout;
public AmazonBannerAdListener(CustomEventBannerListener listener, AdLayout adLayout) {
this.customEventBannerListener = listener;
this.mAdLayout = adLayout;
}
@Override
public void onAdLoaded(Ad ad, AdProperties adProperties) {
customEventBannerListener.onAdLoaded(mAdLayout);
}
@Override
public void onAdFailedToLoad(Ad ad, AdError adError) {
switch (adError.getCode()) {
case NETWORK_ERROR:
customEventBannerListener.onAdFailedToLoad(AdRequest.ERROR_CODE_NETWORK_ERROR);
break;
case NETWORK_TIMEOUT:
customEventBannerListener.onAdFailedToLoad(AdRequest.ERROR_CODE_NETWORK_ERROR);
break;
case NO_FILL:
customEventBannerListener.onAdFailedToLoad(AdRequest.ERROR_CODE_NO_FILL);
break;
case INTERNAL_ERROR:
customEventBannerListener.onAdFailedToLoad(AdRequest.ERROR_CODE_INTERNAL_ERROR);
break;
case REQUEST_ERROR:
customEventBannerListener.onAdFailedToLoad(AdRequest.ERROR_CODE_INVALID_REQUEST);
break;
default:
customEventBannerListener.onAdFailedToLoad(AdRequest.ERROR_CODE_INTERNAL_ERROR);
break;
}
}
@Override
public void onAdExpanded(Ad ad) {
customEventBannerListener.onAdClicked();
}
@Override
public void onAdCollapsed(Ad ad) {
customEventBannerListener.onAdClosed();
}
@Override
public void onAdDismissed(Ad ad) {
customEventBannerListener.onAdClosed();
}
}
| Method | When to call |
|---|---|
onAdLoaded() | The banner request succeeded. |
onAdFailedToLoad() | The banner request failed. |
onAdClicked() | The banner was clicked. |
onAdOpened() | The banner is rendering a full-screen view. |
onAdClosed() | The user returns to the app after clicking on a banner. |
onAdLeftApplication() | The banner caused the user to leave the app. |
// Initialize AdMob AdView
AdView admobAdView = (AdView) findViewById(R.id.newgameactivity_adview_admob);
// Unsure if this is needed
AmazonBannerAd amazonBannerAd = new AmazonBannerAd();
// Sets up AdMob Banner Ad - Should be holding mediated ads - status unknown
AdRequest.Builder builder = new AdRequest.Builder();
builder.addTestDevice(getString(R.string.admob_testdeviceid));
builder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
if (mPrefs.getBoolean(PROFILE_CREATED, false)) {
String gender = mPrefs.getString(GENDER, null);
if (gender != null && gender.matches("male")) {
builder.setGender(AdRequest.GENDER_MALE);
} else if (gender != null && gender.matches("female")) {
builder.setGender(AdRequest.GENDER_FEMALE);
}
String birthday = mPrefs.getString(BIRTHDAY, null);
if (birthday != null) {
DateFormat df = new SimpleDateFormat("MM/dd/yyyy", Locale.US);
try {
Date date = df.parse(birthday);
builder.setBirthday(date);
} catch (Exception e) {
e.printStackTrace();
}
}
}
AdRequest adRequest = builder.build();
admobAdView.loadAd(adRequest);
// Unsure if this is needed
AmazonBannerAd amazonBannerAd = new AmazonBannerAd();
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/lSSE5HP7gKo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The interface I am implementing in the AmazonBannerAdListener is the Amazon AdListener interface. Is that correct? From there, I have to use each of the methods you listed above within the overridden methods from Amazon's AdListener?
I think that is where I am getting lost. The interface I am implementing in the AmazonBannerAdListener is the Amazon AdListener interface. Is that correct? From there, I have to use each of the methods you listed above within the overridden methods from Amazon's AdListener?As for the AmazonBannerAd object, how do I add that into the Admob Adview? Just do "admobAdview.loadAd(amazonBannerAd)"? Would that not just load amazon ads instead of admob's mediated ads?I apologize. I'm very new to programming and self-taught so some of this is over my head. Thank you for your patience.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
// Sample custom event banner.
AdView mCustomEventAdView = (AdView) findViewById(R.id.customevent_adview);
mCustomEventAdView.loadAd(new AdRequest.Builder().build());
Okay, I think I have the Listener set up. Code attached.As for the Admob settings, I have it set for Amazon eCPM higher than Admob (after taking off optimization). This is the setting I had when I first had it set up just to make sure they were working and I was still getting 0 impressions.I'm lost as far as what to do with AmazonBannerAd object after it is initialized. Do I call the requestBannerAd method? Or something else?Thanks for hanging in there with me.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Benjamin,No problem! Thank you for your interest in our SDK. I'll hang in here until we get this working.For your AmazonBannerAd object, I may have mislead you in my earlier message. You do want to use an AdView like you were doing originally. You can see this in action in our mediation example:// Sample custom event banner.
AdView mCustomEventAdView = (AdView) findViewById(R.id.customevent_adview);
mCustomEventAdView.loadAd(new AdRequest.Builder().build());The customevent_adview is created with an ad unit ID that is registered with the name of the the CustomEvent class (for this sample it's com.google.ads.mediation.sample.customevent.SampleCustomEvent). You can view the code for that class in the sample here. It may be a bit confusing because the sample uses that classes for a bunch of different ad types. The SDK populates the AdView based on your custom class instead of the normal AdMob implementation.I've created a sample app for you that fetches Amazon ads through AdMob mediation. I will send you the sample privately because it includes your ad unit ID and class names. Let me know if you have any questions about the implementation!Regards,
Chris FeldmanMobile Ads SDK TeamOn Monday, December 19, 2016 at 5:34:54 PM UTC-5, Benjamin Becker wrote:Okay, I think I have the Listener set up. Code attached.As for the Admob settings, I have it set for Amazon eCPM higher than Admob (after taking off optimization). This is the setting I had when I first had it set up just to make sure they were working and I was still getting 0 impressions.I'm lost as far as what to do with AmazonBannerAd object after it is initialized. Do I call the requestBannerAd method? Or something else?Thanks for hanging in there with me.
To post to this group, send email to google-adm...@googlegroups.com.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/lSSE5HP7gKo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
|
||||||