Created
June 14, 2016 09:59
-
-
Save raymondctc/066a2f4e81b294737a8d92e27257ba9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static View createPublisherAdView(Context context, String adId, final com.google.android.gms.ads.AdListener listener) { | |
try { | |
final PublisherAdView adView = new PublisherAdView(context); | |
adView.setAdUnitId(adId); | |
//adView.setAdSizes(AdSize.SMART_BANNER); | |
adView.setAdSizes(AdSize.BANNER); | |
// if (listener != null) { | |
adView.setAdListener(new AdListener() { | |
@Override | |
public void onAdClosed() { | |
super.onAdClosed(); | |
} | |
@Override | |
public void onAdFailedToLoad(int errorCode) { | |
super.onAdFailedToLoad(errorCode); | |
String msg = "req:" + adView.getMediationAdapterClassName() + " code:" + errorCode; | |
MetricsController.logAds(MetricsController.RLOG_KEY_SHOW_BANNER_AD_FAILED, msg); | |
} | |
@Override | |
public void onAdLeftApplication() { | |
super.onAdLeftApplication(); | |
} | |
@Override | |
public void onAdOpened() { | |
super.onAdOpened(); | |
} | |
@Override | |
public void onAdLoaded() { | |
super.onAdLoaded(); | |
String msg = "req:" + adView.getMediationAdapterClassName(); | |
msg += " h:" + adView.getAdSize().getHeight() + " w:" + adView.getAdSize().getWidth(); | |
MetricsController.logAds(MetricsController.RLOG_KEY_SHOW_BANNER_AD, msg); | |
} | |
}); | |
// } | |
PublisherAdRequest req = newAdRequest(); | |
adView.loadAd(req); | |
// adView.resume(); | |
return adView; | |
}catch (Exception e){ | |
return new View(context); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment