Android Advertising Library

An unified advertising API that supports Google AdMob and Samsung AdHub.


  • Use the same API to display ads from both Google AdMob and Samsung AdHub
  • Ad targeting is supported for both Google and Samsung
  • Easily switch ads between Google and Samsung
  • Simple to use for common use cases

Quick Start

First you must have signed up an account from Google or Samsung. To display ads from Google, you must also install Google Play services. Or if you want to display ads from Samsung, you must also download Samsung AdHub SDK. Then you must import Android Advertising Library to your workspace as a library project.

The Layout

To show ads from Google or Samsung, you need to add a <> element to your layout XML as illustrated in the sample project below.

Add xmlns:ads="", and place your ad to an appropriate location:

    ads:adSize="SMART_BANNER" />

Note: You must replace GOOGLE_AD_UNIT_ID by your Google AdMob Ad ID.

We use SMART_BANNER here to let Google server choose the best-fit size for the ad. You may use other values if you want.

To show ads from Samsung, you need to add a <> element to your layout XML as illustrated in the sample project below.

Place your ad to an appropriate location:

    android:layout_gravity="center" />

How to show ads

First create an instance of AdService:

this.adService = new AdService(context);

Set your ad ID:


Attach a listener to handle various events:

adService.setAdListener(new AdService.AdListener() { ... });

You are ready to display Google ads:

// Displays an ad from Google AdMob.

... or Samsung ads:

// Displays an ad from Samsung AdHub.
adService.displayAd((AdHubView)findViewById(, AdService.getBestFitAdSize(activity));

Ad targeting

Ad targeting is supported by calling the following methods before requesting to show ads:

  • setAge
  • setGender
  • addKeywords

Android Advertising Library provides an unified set of APIs for ad targeting APIs that supports both Google and Samsung.

AdService events

Android Advertising Library provides 2 methods to handle ad loading events for both Google and Samsung:

  • onAdLoaded
  • onAdFailedToLoad

Switch between Google and Samsung ads

By hosting both Google AdView and Samsung AdHubView on your activity, you can load both ads and control which one to display.


Samsung does not allow apps to show ads from a non-Samsung source. You may, however, load ads from Samsung first, and if it fails (as this is often the case), load from Google instead in onAdFailedToLoad callback method.

Sample Project

A sample project is provided to demonstrate all the features.

Built With

Share this project: