An Android Widget which can be used in Android applications to place adverts served by OpenX into a layout.

OpenX Android Widget

This widget was written by Funky Android Ltd. and is made available under the following BSD style license;

Getting Started – OpenX

In order to use the widget you will need to do the following

  1. Open an OpenX Hosted account or download an install the OpenX Server
  2. Follow the video on the OpenX site on getting started with OpenX.
    Please Note: You should create a zone which serves images for the size you need. We use IAB Half Banner (234×60) for the size because it’s small enough to display on a QVGA screen. If you’re only targeting larger displays you can use a larger banner size. You can have multiple zones for one application if you want to control the ads shown in different parts of your application separately.
  3. Get the server name that hosts your adverts.
    You can do this by selecting Zones from the menu on the left, then selecting the Invocation Code option for the appropriate zone from the list, then select Image Tag from the drop down list and press the little arrow to the right of the drop down list, and then look for the image URL in the code provided. In the code for our zone we had …<img src=’…., so the server name for us is
  4. Get the ID of the zone (or zones) you wish to serve in your application.
    The quickest way of doing this we’ve found is to select Zones from the menu on the left, click on the name of the zone you want from the list, and then get the number from the URL (which will end zoneId=xxxx where xxxx is the zone ID).
  5. Make sure you have at least one banner associated with the zone in OpenX, and it must be an image banner.
    Without this there will be nothing for the application to serve so it’ll be difficult to determine if everything is working. You can upload a dummy image if you want, all that is important is that there is something for OpenX to serve.

You’ve now done all you need to do on the OpenX side. You can alter the configuration as you wish, but we’d recommend starting simple so that any potential issues are easily found.

Getting Started – The Android App

There are only three things you’ll need to do to serve ads in your app. These are;

  1. Include the widget source code in your source code tree.
    The only file you need is src/com/funkyandroid/openx/widget/ You should copy this into your applications development tree in the same location.
  2. Include the widget layout definition.
    You can find an example of a layout with the widget included in the demo app at res/layout/main.xml. The widget definition is;


    We’ve set the height to 60px because we’re using a 234×60 pixel banner and setting this lets the OS know how much space the ad needs. We’ve set a background because we think it looked pretty :) .
    The widget is derived from a standard Android ImageView, so any attributes you can set for an ImageView can be set for the widget, but do not set a click listener as this will stop the ad from working.

  3. Set the server name and zone ID in your application.
    In the example application this is done in src/com/funkyandroid/openx/ The important lines are;

    OpenXWidget widget = (OpenXWidget)findViewById(;

    You’ll need to replace the server specified (in our case with the server from step 3 of the OpenX instructions above, and you’ll need to replace the zoneId (in our case 90810) with the zone ID from step 4 of the OpenX instructions above.

You’re then ready to roll.