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?
Thanks in advance,
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?
Thanks in advance,
Copyright © 2021 Jogjafile Inc.
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.
The easy way
The adwhirl layout stays invisible as long as it has nothing to show. So you can simply create a
FrameLayoutcontaining your fallback view in the background and the adwhirl view in the front similar to this:In your code you can then add the view to the layout (where
parentViewis the inflated layout shown above):That's it.
The more sophisticated way
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.
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:
The configuration above ensures, that your custom event will only be fired when AdWhirl isn't able to show any real ads.
Now you need to handle the event in your code. Therefore you need a class that implements the
AdWhirlLayout.AdWhirlInterfaceand 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:Now you need to register your event handler with the
AdWhirlLayoutlike this:That's it.