Skip to content

Instantly share code, notes, and snippets.

@anbykov
Last active December 16, 2015 16:09
Show Gist options
  • Save anbykov/5461454 to your computer and use it in GitHub Desktop.
Save anbykov/5461454 to your computer and use it in GitHub Desktop.
Publisher SDK Integration Guide Android

#Publisher SDK Integration Guide Android

Contents

Introduction

This document describes how to integrate the RadiumOne publisher SDK for Android into your application.

Objective of this document

This document describes how to:

  • Add the SDK files to your project
  • Integrate with Interface Builder
  • Integrate without Interface Builder
  • Shrink, optimize, and obfuscate your code.

Setting up the RadiumOne SDK

What’s Inside

R1‐sdk.jarContains the RadiumOne for Android SDK
Demo ApplicationFully functional Android application that integrates all features of the RadiumOne SDK.
Integration GuideThis document that’s designed to help new developers integrate the RadiumOne for  Android SDK into their applications.

Adding the RadiumOne SDK file to your Project

Drag the “R1‐sdk.jar” file into your project’s libs directory.

Referencing the RadiumOne SDK

Open up your Android project in Eclipse. Click on Properties in the Project menu bar. Select Java Build Path on the left and then select the Libraries tab. Click Add JARs... and select the R1­sdk.jar. The R1­‐sdk.jar should now appear under your project’s Referenced Libraries.

Referencing the RadiumOne SDK (Eclipse)

###Integrating with Your Code

Adding RadiumOne Meta-data and Permissions to the Application

Open your application’s AndroidManifest.xml. Inside the <application> flags, add the following:

  1. R1_SDK_ID
    RadiumOne Application ID.

  2. RadiumOneFullscreenAdView
    An activity used by the RadiumOne SDK to display certain rich media ads and fullscreen advertisements.

Outside of the <application> flags, add or make sure your application has the following permissions:

  1. INTERNET. Used by the RadiumOne Android SDK to fetch advertisements and relay analytics information.
  2. READ_PHONE_STATE. Used to access a unique identifier that some ad networks require to track impressions (See: http://developer.android.com/reference/android/telephony/TelephonyManager.html#getDeviceId() ). The reason some of them choose not to use ANDROID_ID for unique identification is this bug: http://code.google.com/p/android/issues/detail?id=10603
  3. ACCESS_NETWORK_STATE. (Optional) Used to determine the type of network state for analytics and optimized ad serving.

See the following code as an example. The RadiumOne related code is highlighted in green.

AndroidManifets.xml:

<?xml version="1.0" encoding="utf-8"?>  <manifest xmlns:android="http://schemas.android.com/apk/res/android
package="com.radiumone.demo"
android:versionName="1.0.0"
android:versionCode="1">

<application android:icon="@drawable/icon"
android:label="@string/app_name">

<activity android:name=".RadiumOneDemo"
android:label="@string/app_name">
      ...      
</activity> 
    ...

<meta-data android:name="R1_SDK_APP_ID"
android:value="insert-your‐application-key"/>
<activity android:name="com.radiumone.android.sdk.RadiumOneFullscreenAdView"
android:configChanges="orientation|keyboardHidden"/>

</application>
...

Integrating with Interface Builder

  1. Instantiate the RadiumOneAdView into your page’s layout xml:
  2. Adding this code to the xml will create a rectangle in your layout editor representing the RadiumOne AdView for you to position.
      2.1. Finish laying out the RadiumOneAdView in your page's layout.
      2.2. You can now save and close your page's xml file. Your application is now all set to receive ads.

<com.radiumone.android.sdk.
    android:id="@+id/banner_adview"
    android:layout_width="320dip"
    android:layout_height="50dip"
    android:layout_gravity="center" />
RadiumOneAdView

android:layout_width and android:layout_height must be a size that is supported by Radiumone, including
320 x 50 , 300 x 250 , 320 x 480 , 480 x 320

Integrating without Interface Builder

For more advanced implementations of ads, you’ll want to create and place the views in your code. We’re going to show you a basic implementation in your Activity.

Import the RadiumOneBannerAdView class to your Activity , as shown below.

Then, all you need to do is create the view, and add it to your view hierarchy, as shown below.

import com.radiumone.android.sdk.RadiumOneAdView;

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_layout);
  ...

    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(width,height);
  RadiumOneAdView adview = new RadiumOneAdView(this);
  parentView.addView(adview, params);


width and height must be size that supports by R1 ( 320 x 50, 300 x 250, 320 x 480 , 480 x 320) multiplies by
density of device. You can take this value using code below:

  float density = getResources().getDisplayMetrics().density;
  int width = (int)( density * 320 );
  int heigth = (int)( density * 50 );

Integrating a RadiumOne FullScreen AdView

The RadiumOneFullScreenAdView is only available for integration through code. A basic example is provided but it is recommended that you look at the full SDK documentation for full details.

Import the RadiumOneFullScreenAdView class to your Activity , as shown below.

Then, all you need to do is create the view, and add it to your view hierarchy, as shown below.

import com.radiumone.android.sdk.RadiumOneFullscreenAdView;

@Override
public void onCreate(Bundle savedInstanceState) {
...
RadiumOneFullscreenAdView fsAdview = new RadiumOneFullscreenAdView(this);
fsAdView.requestAndDisplayAd();

Adding Listeners for AdViews

For understanding what happening while the ad is loading you can add RadiumOneAdViewListener to AdView. You must implement RadiumOneAdViewListener in your code set it as shown below. If onAdFailedLoad is invoked it means an error occured and an ad not available.

    import com.radiumone.android.sdk.RadiumOneFullscreenAdView;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        ...
        RadiumOneFullscreenAdView fsAdview = new RadiumOneFullscreenAdView(this);
    
        // both views (fullscreen and not fullscreen) has same methods
        fsAdview.setRadiumOneAdViewListener(new CustomListener());
            
        fsAdView.requestAndDisplayAd();
    }
    
    private static class CustomListener implements RadiumOneAdViewListener {
    
        @Override
        public void onAdSuccessfulLoad() {
            Log.i("R1sdk""AD LOADED");
        }
    
        @Override
        public void onAdFailedLoad(int error) {
            Log.i("R1sdk""AD FAILED");
        }
    }

ProGuard

The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names. ProGuard is integrated into the Android build system, so you do not have to invoke it manually. ProGuard runs only when you build your application in release mode, so you do not have to deal with obfuscated code when you build your application in debug mode. Having ProGuard run is completely optional, but highly recommended.

This section describes how to enable and configure ProGuard while using the RadiumOne Android Library.

Configuring the Android Project

In order to use ProGuard tool with the RadiumOne Android Library, you must reference a version of the Android SDK greater than or equal to API level 8. This does not mean that your application requires this API level and can still target lower API levels. The minimum requirement for the RadiumOne Android Library is still API level 3.

Through reflection, the RadiumOne Android Library attempts to use higher levels of Android SDK APIs. If you don’t reference a recent version of the Android SDK, this reflection will fail and ProGuard will throw errors.

Configuring proguard.cfg

Please add the following lines to your proguard.cfg file found in the root of your Android project to ensure that the RadiumOne Android Library will continue to work as expected.

    -keep public class com.radiumone.android.sdk.*
    
    -keepclassmembers class
    com.radiumone.android.sdk.jsinterface.JsMethods {
        public *;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment