Android SDK

From QuattroWiki

Jump to: navigation, search

Contents

Quattro SDK for Android

The Quattro Wireless Android SDK provides a library for displaying ads in applications developed using Java and the Android platform.

This documentation describes the API to integrate the Quattro library into the Android application in order to render ads. Sample code is also provided within the context of several use cases. Developers using this documentation should be familiar with Java and the Android platform.

Once you’ve implemented your code, you can begin testing your site. When you're ready, you can request to go live by clicking the "Submit for Approval" tab in the Manage Sites area. If you have any questions, you can contact your Quattro Account Manager to assist you.

Setting Up Your Project

In order to integrate Quattro's SDK for Android into your application, your application must be built using the Android SDK 1.0, 1.1, 1.5, or 2.0. On the Quattro portal, the latest update supports 2.0. If you are using any of these platforms, then follow the steps below to setup your project.

Before you get started, make sure you have your Quattro Wireless SiteID and PublisherID. You get these values from Quattro once you have created your account. The SiteID corresponds to your application, and the PublisherID corresponds to your company/organization. Keep these values at hand, as you will need them at multiple times during the process to setup your project and to display ads.

To setup your project:

  1. Add qwandroidsdk.jar to your application’s build path.
  2. Add the following permissions to your application:
    • INTERNET
    • READ_PHONE_STATE
    • ACCESS_COARSE_LOCATION
    • ACCESS_FINE_LOCATION
  3. In your res/values directory, create a file called attrs.xml and add the following elements:
    <resources>
    <declare-styleable name="QWAdView">
    <attr name="placement" format="string" />
    <attr name="mediaType" format="string" />
    <attr name="displayMode" format="string" />
    <attr name="adInterval" format="string" />
    <attr name="animation" format="string" />
    <attr name="siteId" format="string" />
    <attr name="publisherId" format="string" />
    <attr name="defaultAdImage" format="string" />
    <attr name="defaultAdClickThru" format="string" />
    <attr name="section" format="string" />
    <attr name="adEventListenerClass" format="string" />
    <attr name="testMode" format="string" />
    <attr name="renderAdOnCreate" format="string" />
    <attr name="requestMode" format="string" />
    <attr name="bgColor" format="string" />
    <attr name="textColor" format="string" />
    </declare-styleable>
    </resources>
  4. Add a custom view called QWAdView to your layout XML (see the example listed here), and substitute the values you want. Make sure to use the SiteID and PublisherID provided by Quattro. For a complete list of parameters and values, see Ad Request Configuration for Android and Attribute Values for Android.
    <com.qwapi.adclient.android.view.QWAdView
    android:id="@+id/QWAd"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    qwad:siteId="siteId"
    qwad:publisherId="pubId"
    qwad:mediaType="banner"
    qwad:displayMode="normal"
    qwad:placement="top"
    qwad:animation="slide"
    qwad:defaultAdImage="@drawable/sample"
    qwad:adEventListenerClass=" Implementation class of the com.qwapi.adclient.android.AdRequestorEventsListener interface"
    />
    The following is a sample minimum configuration that renders ads.
<com.qwapi.adclient.android.view.QWAdView
android:id="@+id/QWAd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
qwad:siteId="siteId"
qwad:publisherId="pubId"
qwad:mediaType="banner"
/>
5. Add the name space declaration to your layout XML file.
Important: Please note that the package name in the example (com.example.android.lunarlander) should be replaced with your application’s package name.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:qwad="http://schemas.android.com/apk/res/com.example.android.lunarlander"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

Displaying Ads

There are two simple ways to display ads in your application. You can use either of these methods, depending on your preference:

  • Approach 1: Add a custom view called QWAdView in your activity’s layout XML and configure the necessary properties.
  • Approach 2: Construct the QWAdView object from your activity and add this as one of the content views of your activity.

Regardless of the approach you choose, you will need to configure a number of properties to display ads. For a complete list of parameters and values, see Ad Request Configuration for Android and Attribute Values for Android.

Approach 1: Adding a Custom View

To add a custom view to your layout XML:

  1. Add an XML element as in the example listed here. In this example, the element renders a banner ad in your application with an animation effect. If no ad is returned from the Ad Server, it displays a default ad image in place of an ad.
    <com.qwapi.adclient.android.view.QWAdView
    android:id="@+id/QWAd"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    qwad:siteId="siteId"
    qwad:publisherId="pubId"
    qwad:mediaType="banner"
    qwad:defaultAdImage="@drawable/sample"
    />
  2. Substitute your SiteID and PubID, and configure the remaining properties. For a complete list of parameters and values, see Ad Request Configuration for Android and Attribute Values for Android.

Approach 2: Creating the QWAdView Object

To create an AdView dynamically from your code:

  1. Add the following lines of code in your activity:
    adView = new QWAdView(this,"itest3","b33eb94ffbce48bd8301a5476039cb63",MediaType.banner,Placement.top,
    DisplayMode.autoRotate, 30, AnimationType.slide, new AdRequestorEventsListener(), true);
    this.addContentView(adView,adView.getLayoutParams());
  2. Substitute your SiteID and PubID, and configure the remaining properties. For a complete list of parameters and values, see Ad Request Configuration for Android and Attribute Values for Android. The constructor (shown in Step 1) takes the following parameters in the following order:
    android.content.Context, SiteId, PublisherId, MediaType, Placement, DisplayMode, AdInterval, AnimationType,
    EventListener, renderAdOnCreate

Using the Sample Applications

Sample applications are included in your downloaded SDK package, in the Samples directory. Two applications are included: LunarLander and Snake. These samples have been integrated with the Quattro Wireless SDK. To follow these steps, you need to have Eclipse installed with the ADT plugin.

To use a sample application:

  1. Unzip the package to a directory.
  2. Choose File -> New -> Android Project.
  3. Check Create project from existing source.
  4. Browse to the location of where the sample application is located, for example: <package unpack dir>/samples/LunarLander.
  5. Click Finish.
  6. Select the project, and choose Properties from the right click menu.
  7. Select Java Build Path.
  8. Click Add External Jars, and navigate to the location of qwandroidsdk.jar (in the projects libs directory).
  9. Click Finish.
  10. From the Run As icon, select the LunarLander project. This launches the emulator and starts the LunarLander application. The apk files that are generated may then be loaded onto a phone.

The same steps may be followed to setup the Snake application and run it within the emulator.

For More Information

Personal tools