Integration Guide 2.2 - uc-union/union-ads-sdk-demo GitHub Wiki

Integration Guide - 2.2


1. SDK Introduction

Please refer to Home

2. Environment Configuration

SDK requires Android SDK level 11 or above.

Note: SDK is released in aar, and you can find it HERE

2.1. Android Studio (Highly recommended)

If you employ Eclipse as the development environment, please go to 2.2. Eclipse

Add the following repositories info to build.gradle, more details in build.gradle line 22-24

repositories {
    maven {
        url 'https://raw.githubusercontent.com/uc-union/union-ads-maven-repository/master'
    }
}

Add dependencies dependency(usually defined in app/build.gradle), more details in app/build.gradle line 44

dependencies {
    compile 'com.ucweb.union.ads:unionads:2.2.+'
}

2.2. Eclipse

Note: If you use Android Studio, you can skip this section.

Download aar to local directory and decompress, you'll get the following directory layout.

unionads_xxx.aar
    |--(Directories)
    |--AndroidManifest.xml
    |--proguard.txt
    |--classes.jar

Follow the steps below,

  1. Rename classes.jar to unionads.jar, and put it in the libs directory

  2. Merge AndroidManifest.xml into AndroidManifest.xml of the developer's project

  3. Merge proguard.txt into proguard.pro of the developer's project.

2.3. Aggregate third-party ad network inventory

Union Ad SDK supports the aggregation of inventories of Facebook and AdMob, you can choose to aggregate one or more of them based on your needs.

3. API Reference

More details refer to API-Reference-2.2

3.1. Initialize SDK

Use UnionAdsSdk.start() in onCreate() of Application to activate and initialize Ad SDK

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        ...
        UnionAdsSdk.start(this);
    }
}

Note: If Application is not defined by the app,you need to derive one and define it in AndroidManifest.xml

For more sample codes, please refer to: UnionAdsSdkSampleApp & AndroidManifest.xml

3.2. Banner

Banner ad is provided to dvelopers in the form of Android View. Developers can set its placement and size with great flexibility. Examples for banner ad codes are listed below,

final BannerAdView adView = new BannerAdView(MainActivity.this);
adView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded(UnionAd ad) {
    }
    @Override
    public void onAdClosed(UnionAd ad) {
    }
    @Override
    public void onAdShowed(UnionAd ad) {
    }
    @Override
    public void onAdClicked(UnionAd ad) {
    }
    @Override
    public void onAdError(UnionAd ad, AdError adError) {
    }
});
AdRequest adRequest = AdRequest.newBuilder()
        .pub("ssr@debugbanner")
        .build();
adView.loadAd(adRequest);

Note: Currently, banner ads only support using API via source-code. Banner ads do not support using API through direct configuration in xml file.

For more sample codes, please refer to: BannerFragment

3.3. Interstitial

Interstitial ad is displayed in the form of an inserted UI (half screen dialog box or full-screen UI).

Examples for interstitial codes are listed below,

final InterstitialAd interstitial = new InterstitialAd(MainActivity.this);  
interstitial.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded(UnionAd ad) {
        interstitial.show();
    }
    @Override
    public void onAdClosed(UnionAd ad) {
    }
    @Override
    public void onAdShowed(UnionAd ad) {
    }
    @Override
    public void onAdClicked(UnionAd ad) {
    }
    @Override
    public void onAdError(UnionAd ad, AdError adError) {
    }
});
AdRequest adRequest = AdRequest.newBuilder()
        .pub("ssr@debuginterstitial")
        .build();
interstitial.loadAd(adRequest);

Note: You should invoke show() in InterstitialAd when onAdLoaded is called back, or Interstitial won't show correctly.

For more sample codes, please refer to: InterstitialFragment

3.4. Native Ad

Native ads are the type of ads Ad SDK can offer, where developers enjoy the greatest flexibility. Ad SDK only returns the relevant sources of the ads to the developer, and developer himself would decide the placement, size and layout of the ads. It should be noted that, because the SDK needs to deal with some events related to the ads internally, developers should associate the final View of the ads to the native ads via registerViewForInteraction.

When Native ads send out requests to designate the specific size for the ads using AdRequestCoverImageSize (the size of the image on the cover), the SDK would find the ads of the most suitable size.

Note: Native ads will not load images by default,you can use ImageDownloader provided by the SDK to load images, if necessary.

Examples of native ad codes are as follows:

final NativeAd nativeAd = new NativeAd(
        MainActivity.this);
nativeAd.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded(UnionAd ad) {
        NativeAdAssets assets = nativeAd.getNativeAdAssets();
        /* ... */
    }
    @Override
    public void onAdClosed(UnionAd ad) {
    }
    @Override
    public void onAdShowed(UnionAd ad) {
    }
    @Override
    public void onAdClicked(UnionAd ad) {
    }
    @Override
    public void onAdError(UnionAd ad, AdError adError) {
    }
});
AdRequest adRequest = AdRequest.newBuilder()
        .pub("ssr@debugnative")
        .build();
nativeAd.loadAd(adRequest);

For more sample codes, please refer to: NativeFragment

4. FAQ

For more details, see Frequently-Asked-Questions

⚠️ **GitHub.com Fallback** ⚠️