Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
中介和CustomEventBanner java_Java_Admob - Fatal编程技术网

中介和CustomEventBanner java

中介和CustomEventBanner java,java,admob,Java,Admob,我想创建一个CustomEventBanner,但有一些问题。我不确定我是否在正确的地方做了正确的事情。我应该在哪里将横幅添加到布局中?我必须调用CustomEventBannerListener的每个方法吗?哪些是绝对必要的?我如何知道是否没有要显示的广告(没有通知) 实际上,我可以使用admob显示广告,但不使用我的自定义广告:( 这是我的密码: public class CustomAd implements CustomEventBanner, AdResponseHandler { p

我想创建一个CustomEventBanner,但有一些问题。我不确定我是否在正确的地方做了正确的事情。我应该在哪里将横幅添加到布局中?我必须调用CustomEventBannerListener的每个方法吗?哪些是绝对必要的?我如何知道是否没有要显示的广告(没有通知)

实际上,我可以使用admob显示广告,但不使用我的自定义广告:(

这是我的密码:

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可以侦听这些事件