中介和CustomEventBanner java
我想创建一个CustomEventBanner,但有一些问题。我不确定我是否在正确的地方做了正确的事情。我应该在哪里将横幅添加到布局中?我必须调用CustomEventBannerListener的每个方法吗?哪些是绝对必要的?我如何知道是否没有要显示的广告(没有通知) 实际上,我可以使用admob显示广告,但不使用我的自定义广告:( 这是我的密码:中介和CustomEventBanner java,java,admob,Java,Admob,我想创建一个CustomEventBanner,但有一些问题。我不确定我是否在正确的地方做了正确的事情。我应该在哪里将横幅添加到布局中?我必须调用CustomEventBannerListener的每个方法吗?哪些是绝对必要的?我如何知道是否没有要显示的广告(没有通知) 实际上,我可以使用admob显示广告,但不使用我的自定义广告:( 这是我的密码: public class CustomAd implements CustomEventBanner, AdResponseHandler { p
public class CustomAd implements CustomEventBanner, AdResponseHandler {
private CustomEventBannerListener bannerListener;
protected SASBannerView mBannerView;
@Override
public void requestBannerAd(final CustomEventBannerListener listener,
final Activity activity, String label, String serverParameter,
AdSize adSize, MediationAdRequest mediationAdRequest, Object extra) {
// 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.
// Create banner instance
mBannerView = new SASBannerView(activity);
// Set the listener to register for events.
this.mBannerView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
listener.onClick();
} catch (Throwable t) {
}
}
});
// Load the ad with the ad request giving an AdResponseHandler
mBannerView.loadAd(42295, "286177", 18008, true, "", this);
}
@Override
public void destroy() { // The destroy method gets called when the mediation
// framework refreshes
// and removes the custom event. Perform any necessary cleanup here.
if (this.mBannerView != null) {
this.mBannerView.onDestroy();
}
}
@Override
public void adLoadingCompleted(SASAdElement arg0) {
this.bannerListener.onReceivedAd(this.mBannerView);
}
@Override
public void adLoadingFailed(Exception arg0) {
this.bannerListener.onFailedToReceiveAd();
}
}
代码看起来相当不错。虽然您的横幅除了通知
onClick()
,在单击时似乎什么也没做。如果您的横幅最终碰到了外部web浏览器或播放商店,您也可以在onClickListener中调用onPresentScreen()
和onLeaveApplication()
请注意,这只是应用程序的自定义事件组件,用于实现SAS网络。您的主要活动仍然需要创建一个AdView(将中介ID设置为针对自定义事件),并将广告加载到其中
只有onReceivedAd
和onFailedToReceiveAd
对于中介的运行是绝对必要的。其他选项非常有用,以便主AdView的AdListener可以侦听这些事件