处理AdWhirl onFailure [英] Handle AdWhirl onFailure

查看:150
本文介绍了处理AdWhirl onFailure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我工作的一个Android应用程序,并使用AdWhirl,以显示我的广告。我希望能够处理这种情况时,AdWhirl返回任何广告。当它失败时,我想表明一个装饰吧。

Hi I am working on an android app and using AdWhirl to display my ads. I want to be able to handle the situation when AdWhirl returns no ads. When it fails, I want to show a decorative bar.

谁能给我一个例子吗?

Can anyone provide me an example?

在此先感谢,

推荐答案

好,我现在想通了这一点。有两种可能的方式,其中一个是非常容易和其他需要一点点的工作

OK I've figured this out now. There are two possible ways, where one is very easy and the other requires a little bit more work.

的adwhirl布局保持不可见,只要它没有任何显示。因此,你可以简单地在后台创建一个的FrameLayout 包含你的后备视图和adwhirl鉴于前面类似这样:

The adwhirl layout stays invisible as long as it has nothing to show. So you can simply create a FrameLayout containing your fallback view in the background and the adwhirl view in the front similar to this:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="53dp"
        android:layout_gravity="center_horizontal"
        >
    <!-- fallback view -->
    <TextView
        android:id="@+id/ad_fallback"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:text="nothing to say..."
        >
</FrameLayout>

在你的code则可以将视图添加到布局(其中 parentView 是上面显示的膨胀布局):

In your code you can then add the view to the layout (where parentView is the inflated layout shown above):

final DisplayMetrics dm = activity.getResources().getDisplayMetrics();
final AdWhirlLayout adView = new AdWhirlLayout(activity, ADWHIRL_ID);
adView.setMaxWidth((int) (dm.density * 320));
adView.setMaxHeight((int) (dm.density * 53));
adView.setGravity(Gravity.CENTER);
parentView.addView(adView);

就是这样。

好消息虽然我想要一个更复杂的方式:广告载入中...信息应显示同时AdWhirl正忙于获取广告,如果它没有任何填充在内部的广告横幅(作为资源的应用程序,因此,它甚至可以,如果网络不可用)应该显示。加载消息是很容易的,因为它可以实现如上图所示,但动态的内部旗帜更棘手一点。

In GoodNews though I wanted a more sophisticated way: An "ad loading ..." message should be shown while AdWhirl is busy fetching ads and if it has nothing to fill in an internal ad banner (provided as resource in the app, so that it even works if internet is not available) should be displayed. The loading message is easy, as it can be implemented like shown above, but the dynamic internal banner is a little bit more tricky.

该解决方案是由AdWhirl提供强大的自定义事件这是 - 遗憾的是 - 很糟糕的记录。第一步采取是建立在AdWhirl Web界面的自定义事件:

The solution are the mighty custom events provided by AdWhirl which are -- unfortunately -- badly documented. The first step to take is to create a custom event in the AdWhirl web interface:

  1. 在弹出的广告网络设置
  2. 点击广告自定义事件按钮,在顶部
  3. 输入任意名称(如回退)和函数名(后者将直接映射到一个方法名的Java类)
  4. 启用事件在给它的0%分配
  5. 现在,调出回填优先屏幕,移动你的备用事件清单
  6. 的结束

以上保证了配置,当AdWhirl不能表现出任何真正的广告自定义的事件只被解雇。

The configuration above ensures, that your custom event will only be fired when AdWhirl isn't able to show any real ads.

现在你需要处理的事件在code。因此,您需要实现 AdWhirlLayout.AdWhirlInterface ,并定义了一个公共的方法不带参数,一个名字等于在自定义事件中指定的函数名称的类。然后,该方法可以在特定视图注入AdWhirl布局:

Now you need to handle the event in your code. Therefore you need a class that implements the AdWhirlLayout.AdWhirlInterface and defines a public method without parameters and a name equal to the function name specified by the custom event. This method can then inject your specific view into the AdWhirl layout:

class AdWhirlEventHandler implements AdWhirlLayout.AdWhirlInterface {
    private final AdWhirlLayout adView;

    public AdWhirlEventHandler(AdWhirlLayout adView) {
        this.adView = adView;
    }

    @Override
    public void adWhirlGeneric() {
        // nothing to be done: Generic notifications should also be 
        // configurable in the AdWhirl web interface, but I could't find them
    }    

    /**
     * Will be called by AdWhirl when our custom event with the function name 
     * "fallback" is fired. Called via reflection.
     */
    public void fallback() {
        try {
            final View fallbackView = 
                ... // inflate the view to be shown here
            adView.pushSubView(fallbackView);

            /*
             * reset backfill chain and schedule next ad update
             */
            adView.adWhirlManager.resetRollover();
            adView.rotateThreadedDelayed();
        } catch (MyExpectedException ex) {
            /*
             * forward to next option from the backfill list
             */
            adView.rolloverThreaded();             
        }
    }
}

现在你需要用你注册的事件处理程序的 AdWhirlLayout 是这样的:

Now you need to register your event handler with the AdWhirlLayout like this:

adView.setAdWhirlInterface(new AdWhirlEventHandler(adView));

就是这样。

这篇关于处理AdWhirl onFailure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆