Handle AdWhirl onFailure

Hi, I am working on an Android app and use AdWhirl to serve my ads. I want to be able to handle a situation where AdWhirl does not return ads. When he fails, I want to show a decorative bar.

Can someone provide me an example?

Thanks in advance,

+4
source share
1 answer

OK. I get it now. There are two possible ways when one of them is very simple and the other requires a little more work.

Easy way

The adwhirl layout remains invisible until it has nothing to show. That way, you can simply create a FrameLayout containing your backup view in the background, and an ad view in the front end 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> 

In your code, you can add a view to the layout (where parentView is the bloated 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); 

What is it.

More complicated way

In GoodNews , although I need a more complicated way: the Ad adload message ... should be displayed while AdWhirl is running and if it has nothing to fill in the internal advertising banner (provided as a resource in the application, so that it works even if the Internet wasnโ€™t available) should be displayed. Posting a message is easy, as it can be implemented as shown above, but a dynamic internal banner is a bit more complicated.

The solution is the powerful custom events provided by AdWhirl, which, unfortunately, are poorly documented. The first step is to create a custom event in the AdWhirl web interface:

  • display "Ad Network Settings"
  • click the "Custom Event" button at the top
  • enter an arbitrary name (for example, "backup") and the name of the function (the latter will directly match the name of the method in your Java class)
  • enable the event when assigning it 0%
  • Now raise the Backfill Priority screen and move the backup event to the end of the list.

The configuration above ensures that your custom event will only be fired if AdWhirl is unable to display any real ads.

Now you need to handle the event in the code. Therefore, you need a class that implements AdWhirlLayout.AdWhirlInterface and defines a public method without parameters and a name equal to the name of the function specified by the custom event. This method can then enter 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(); } } } 

Now you need to register the event handler using AdWhirlLayout as follows:

 adView.setAdWhirlInterface(new AdWhirlEventHandler(adView)); 

What is it.

+5
source

Source: https://habr.com/ru/post/1342135/


All Articles