Android integration - OutbidIO/Outbid-SDK GitHub Wiki

Setting up your project

Prequisities

  • include google play services ads as a dependency in your project
  • Developing for android api 9 and above

Add outbid.jar to your project libs

Download outbid.jar file and add it to your project libs folder. Make sure you have this line in your app level gradle file:

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])

AndroidManifest.xml:

Add the following permissions under the manifast tag:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>

Optional If you have Facebook Audience ads in your project - make sure you add this activity under the application tag:

<!-- Facebook audience -->
<activity android:name="com.facebook.ads.AudienceNetworkActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />

Code integration

sdk initialization

In your first activity onCreate method add this call to initialize the sdk:

OutbidManager.getInstance().init(this, "devId", "appId");

replace "devId" and "appId" with ids you receive from outbid team

If you display interstitial ads in your app add this line after initialization - this will Cache ads for later use:

OutbidManager.getInstance().loadInterstitial();

you must make this call if you wish to show interstitial ads in your app

you only have to call this once

Interstitial ads:

Show interstitial:

if(OutbidManager.getInstance().isInterstitialAvailable())
   OutbidManager.getInstance().showInterstitial();

isInterstitialAvailable return true if ad is available for display

(Optional) Interstitial callbacks:

OutbidManager.getInstance().setInterstitialAdListener(new OBInterstitialAdListener() {
   @Override
   public void onInterstitialLoaded() {
       // code to be executed when interstitial ad loaded
   }
   @Override
   public void onInterstitialFailedToLoad(int i) {
       // code to be executed when interstitial ad failed to load.
       // call Log.AdErrorCodes.getErrorDesc(i) to get the error desc
   }
   @Override
   public void onInterstitialOpen() {
       // code to be executed when interstitial ad opened
   }
   @Override
   public void onInterstitialClosed() {
       // code to be executed when interstitial ad closed
   }
});

Banner ads:

Show banner:

OutbidManager.getInstance().showBanner(this,OutbidBannerPostition.BOTTOM);

notice that the second param indicate what position in the screen to display the banner

In order to specify banner type you can add third param to the call:

OutbidManager.getInstance().showBanner(this, OutbidBannerPostition.BOTTOM, OutbidBannerSizes.BANNER);

Hide banner:

OutbidManager.getInstance().hideBanner(this);

(Optional) banner callbacks:

OutbidManager.getInstance().setBannerListener(new OBBannerListener() {
   @Override
   public void onBannerLoaded() {
       // code to be executed when banner loaded and displayed on screen
   }
   @Override
   public void onBannerFailedToLoad(int i) {
       // code to be executed when banner failed to load
       // to get the error desc call AdErrorCodes.getErrorDesc(i)
   }
});

available banner positions:

OutbidBannerPosition.TOP - middle top of the screen
OutbidBannerPosition.TOP_RIGHT - right top of the screen
OutbidBannerPosition.TOP_LEFT - left top of the screen
OutbidBannerPosition.BOTTOM - middle bottom of screen
OutbidBannerPosition.BOTTOM_RIGHT - right bottom of screen
OutbidBannerPosition.BOTTOM_LEFT - left bottom of screen

Obtaining a Banner view and placing it in a layout xml:

You can choose to integrate banner inside your existing layout in a custom position.

for this purpose you can obtain a banner instance:

First - define a container for the banner in your layout xml file

For example in order to display banner on bottom of the screen add this to your activity layout file:

<LinearLayout
android:id="@+id/banner_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"/>

Second - declare and obtain a banner view and an ad request instance:

com.google.android.gms.ads.doubleclick.PublisherAdView banner;
com.google.android.gms.ads.doubleclick.PublisherAdRequest adRequest;

protected void onCreate(Bundle savedInstanceState) {
...
banner = OutbidManager.getInstance().getBanner(this, OutbidBannerSizes.BANNER);
adRequest = OutbidManager.getInstance().getAdRequest();

Third - add banner callbacks (mandatory step):

            banner.setAdListener(new AdListener() {
                boolean retry = true;
                // called when an ad is closed
                @Override
                public void onAdClosed() {
                    super.onAdClosed();
                }
                // called when an ad fail to load
                @Override
                public void onAdFailedToLoad(int i)
                {
                    super.onAdFailedToLoad(i);
                    if (retry) {
                        Log.i(TAG, "banner failed to load - loading fb banner");
                        PublisherAdRequest adRequest = OutbidManager.getInstance().getFBBannerAdRequest();
                        if(adRequest!=null)
                        {
                            retry = false;
                            banner.loadAd(adRequest);
                        }
                        else
                        {
                            Log.i(TAG, "no fallback available aborting");
                        }
                    } else {
                        Log.i(TAG, "fb banner failed");
                    }
                }
                // called when an ad is clicked
                @Override
                public void onAdLeftApplication() {
                    super.onAdLeftApplication();
                }
                // called when an ad is open
                @Override
                public void onAdOpened() {
                    super.onAdOpened();
                }
                // called when an ad is loaded
                @Override
                public void onAdLoaded() {
                    super.onAdLoaded();
                    retry = true;
                }
            });

Notice that if the banner request fails first time there is another call to a fall back banner. This is very important in order to ensure high fill-rate and maximize revenues

Lastly - load the banner and add it to your layout:

LinearLayout adContainer = (LinearLayout) findViewById(R.id.banner_container);
// Add the ad view to your activity layout
adContainer.addView(banner);
// Request an ad
banner.loadAd(adRequest);

**You should only attach the banner instance once to your banner container view.

When you want to hide the banner use this code:

if(banner!= null)
{
    bannerBottom.pause();
    bannerBottom.setVisibility(View.GONE); 
}

When you wish to show the banner again make it visible again:

if(banner!= null)
{
    bannerBottom.resume();
    bannerBottom.setVisibility(View.VISIBLE); 
}

When you no longer going to use the banner for example when the activity is destroyed call this to release banner resources:

if(banner!= null)
{
    banner.setVisibility(View.GONE);
    banner.destroy();
}

banner sizes:

public static int BANNER = 0 ; // 320*50
public static int MEDIUM_RECTANGLE = 1; // 300*250
public static int FULL_BANNER = 2; // 468*60
public static int LARGE_MOBILE_BANNER = 3; // 320*100

Monitor outbid flow:

You can filter the log cat with “outbid” tag in order to monitor for sdk integration status and possible errors.