Integration Guide 2.2 - uc-union/union-ads-sdk-demo GitHub Wiki
Please refer to Home
SDK requires Android SDK level 11 or above.
Note: SDK is released in aar, and you can find it HERE
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.+'
}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,
-
Rename
classes.jartounionads.jar, and put it in thelibsdirectory -
Merge
AndroidManifest.xmlintoAndroidManifest.xmlof the developer's project -
Merge
proguard.txtintoproguard.proof the developer's project.
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.
More details refer to API-Reference-2.2
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
Applicationis not defined by the app,you need to derive one and define it inAndroidManifest.xml
For more sample codes, please refer to: UnionAdsSdkSampleApp & AndroidManifest.xml
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
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 whenonAdLoadedis called back, or Interstitial won't show correctly.
For more sample codes, please refer to: InterstitialFragment
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
ImageDownloaderprovided 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
For more details, see Frequently-Asked-Questions
