Showing OpenX Ads in Android Applications

This post is also available in: Russian

The mobile advertising market is constantly gaining momentum, and many Android application developers are interested in ads based content monetization. Most of them use the services of AdMob, the largest provider of mobile advertising. But AdMob is in no way the only alternative. An open and free OpenX Web advertising server can also be used to show ads in mobile applications. In this post, we will show how to do this and who may benefit from it.

Here are the four reasons for you to choose an open source solution rather than a popular one:

  1. You are an enthusiast of online advertising and you are eager to understand how the things work, preferring to do everything yourself.
  2. You can not use the services like AdMob, as you do not meet their requirements to applications or promotional materials.
  3. You want to deploy an advertising server within your infrastructure. For example, you may need to run an application within a closed network with no Internet access, or you simply do not trust Google.
  4. You need to make a highly customized solution to satisfy non-standard requirements for targeting, reporting, etc.

In order to simplify insertion of OpenX ads into your Android application, we wrote a widget that can be embedded into any application using standard tools provided by the platform. You can download an archive with the source code of the widget, its documentation and use cases from here or from labs.denivip.ru.

The component was successfully tested with OpenX Community Edition 2.8.8-rc6 (the latest version at the moment), but it should also be compatible with the earlier versions. In fact, this is a WebView component enhanced with an easy-to-use software interface enabling ads loading from OpenX. To use the widget, simply add its description to a layout XML relating to your activity. For example:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:ox="http://denivip.ru/schemas/android/openx/0.1"
            android:orientation="vertical"
            android:layout_width="match_parent"

            android:layout_height="match_parent">
  <ru.denivip.android.widgets.OpenxAdView
            android:id="@+id/adview"
            android:layout_width="88px"
            android:layout_height="31px" 
            ox:delivery_url="@string/openxDeliveryUrl"

            ox:zone_id="3" />
  <ListView android:layout_width="match_parent"
            android:id="@+id/contactList"
            android:layout_height="wrap_content"

            android:layout_weight="1"/>
</LinearLayout>

In the OpenXad layout, please specify all standard parameters of the View component, as well as the following banner delivery options:

  • delivery_url — the path to the OpenX server and its directory storing ads delivery scripts. For example: openx.example.com/delivery.
  • js_tag_url — name of the OpenX script responsible for delivery of your ad code with a standard JavaScript tag. In most cases, you do not need to change this option as it defaults to ajs.php, a standard script from the OpenX installation.
  • zone_id — the identifier of an OpenX zone to choose ads from. This parameter is mandatory unless you explicitly specify it in the load(int) ad load method.
  • has_https — to enable HTTPS data exchange with the OpenX server, set this value to true. The default value is false.
  • source — this parameter is optional and applies to targeted advertising.

You may specify all of these parameters or add the OpenXAd component directly to the application code (i.e., skipping the layout file).

As a result, the activity screen of your application will show an area of the specified size containing a banner loaded from the OpenX server (see the snapshot at the top of the page). Similarly to a Web page, this banner is clickable to refer to the advertiser’s site.

We welcome your feedback and comments on the OpenXAd widget.

android-widget.tar.gz

Leave a Reply