Skip to content
Vladyslav Bilohorodskyi edited this page Feb 1, 2017 · 28 revisions

Requirements

SmartyAds in-app advertising SDK requires Android SDK version 14 or higher.

#Getting Started

Just a few steps to start:

  1. Register your account on SmartyAds Supply Side Platfrom.

  2. Confirm your registration by clicking the confirmation link on the email.

  3. Create your first mobile inventory, it should be reviewed and approved.

  4. After this, you will be granted access to create placements for your inventory, Add Placement button should become clickable.

  5. Click on Add Placement, add the targeting options, floor price and size of your placement, then save your changes.

  6. Please note the Placement ID(e.g., ID#1234) below it's title. It will be used later in your code to initialize ad container.

Installation

  • Download aar lib: ad-container-release.aar
  • In Android studio: File -> New -> New Module and choose Import .jar/.aar Package, press next
  • File name: path to aar
  • File -> Project Structure -> {your_module_tab} -> dependencies and add just imported module as dependency

Setup App Permissions (optional)

Edit your Android manifest to include the following (optional but recommended) permissions:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.smartyads.sampleapp">
    
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />  <!-- Grants the SDK permission to access a more accurate location based on GPS -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!-- Grants the SDK permission to access approximate location based on cell tower -->
 
	<!-- your app description -->
</manifest>

SmartyAds SDK already has the following normal permissions required by the SDK:

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

Setting up required parameters in strings.xml

Set the app distribution type(required by SDK) in your strings.xml file:

<integer name="distribution_type">{0|1}</integer>

where:

  • 0 - app is free
  • 1 - the app is a paid version Now, add the banner_id to strings.xml

<string name="banner_id">{your_banner_id_here}</string>

Important! Do not forget to replace the your_banner_id_here with placement ID from the Platform(Step 6 of the Getting Started section) e.g, <string name="banner_id">{_1234_}</string>

Initialize SmartyAds SDK

Extend android.app.Application class, override #attachBaseContext(Context) method and call com.smartyads.SmartyAds#init(Context) method as shown below:

public class SampleApp extends Application {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        SmartyAds.init(base);
    }
}

Show Banners

You can configure your banner ad view using XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:smartyads="http://schemas.android.com/apk/res-auto">

	<com.smartyads.adcontainer.BannerContainer
    	android:id="@+id/banner_container"
    	android:layout_width="wrap_content"
    	android:layout_height="wrap_content"

    	smartyads:bannerId="@string/banner_id"
    	smartyads:banner_width="300dp"
    	smartyads:banner_height="250dp"/>

</LinearLayout>

Where

  • smartyads:bannerId="@string/banner_id" - placement Id that you received when you had created new inventory http://beta.ssp.smartyads.com/publisher/inventory
  • smartyads:banner_width="300dp" - placement width
  • smartyads:banner_height="250dp" - placement height

Make sure that xmlns:smartyads="http://schemas.android.com/apk/res-auto" was added to your root layout

Finally, call BannerContainer#showOnLoad()

BannerContainer bannerContainer = (BannerContainer) findViewById(R.id.banner_container);
bannerContainer.loadAd();

Also, there is alternative method BannerContainer#showOnLoad(BannerOnLoadListener) that would be useful if you want to know whether banner was loaded successfully or not

bannerContainer.loadAd(new BannerOnLoadListener() {
            @Override
            public void onSuccess() {
                Log.d("YOUR_TAG","Banner succesfully loaded");
            }

            @Override
            public void onFailure(Exception e) {
                Log.e("YOUR_TAG","Cannot load ad: " + e.getMessage());
            }
        });

Also, dont forget to call BannerContainer#destroyContainer() in Activity#onDestroy() method to prevent memory leaks

@Override
protected void onDestroy() {
    bannerContainer.destroyContainer();
    super.onDestroy();
}
Clone this wiki locally