gpt4 book ai didi

android - Admob 中介中的自定义事件添加不受支持的广告网络

转载 作者:太空狗 更新时间:2023-10-29 12:51:36 26 4
gpt4 key购买 nike

我已阅读有关如何在 Admob 中介中实现自定义事件的所有内容。我已经添加了完整的打包类名称,所有内容都在 Admob 门户中设置。

这是完成的类实现

  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();
}


}

问题是我真的不知道如何在 onReceivedAd() 中添加使用我的 layout.add(adview),

任何输入都会有所帮助。

最佳答案

与普通的 AdMob 实现相比,自定义事件略有不同。在 requestBannerAd 中,您创建广告网络的广告 View ,并请求广告。收到广告后(在此 onReceiveAd 回调中),您调用:

this.bannerListener.onReceivedAd(this.adView);

您已经在您的代码中这样做了。调用它时,您是在告诉 AdMob 中介层“嘿,我成功加载了一个广告,这是我的 View 供您显示。”中介层接受您的 adview 并代表您调用 layout.addView(adView)(它将其添加为您在应用中定义的主 AdView 的子级)。

因此在您的情况下,这段代码应该可以正常工作。

关于android - Admob 中介中的自定义事件添加不受支持的广告网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11667285/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com