In this tutorial we show how to integrate the ArenaDaemon's ADV feature into an Android application.

More in depth, we are going to show how to display advertising banners and videos.

 

We assume that the developer already owns an account into the ArenaDaemon web platform and

owns the knowledge for creating a new application and retrieving the correspondent appKey.

For more information about how to create a developer account and for setup a new application,

please refer to the chapter "Create an appKey".

  

Create a new Android project and include the SDK as shown in chapter SDK Installation and setup.

 

The next step is to create an Activity (we'll give it the name 'MainActivity') in which

we'll load a banner and a clip.

 

Before doing any action with the daemons, the local player needs to be authenticated so we need

to add the following code to the MainActivity class :

 

 

protected void onCreate(Bundle savedInstanceState) {

 

        super.onCreate(savedInstanceState);

        setContentView(R.layout.layout_main);

 

        // container view for banner

        bannerContainer = (RelativeLayout) findViewById(R.id.banner_container);

 

        // container view for clip

        clipContainer = (RelativeLayout) findViewById(R.id.clip_container);

 

        // buttons

        startStopBannerRotationButton = (Button)

                        findViewById(R.id.start_stop_banner_rotation_button);

 

        startStopBannerRotationButton.setOnClickListener(this);

        

        getAdClipButton = (Button) findViewById(R.id.get_ad_clip_button);

        getAdClipButton.setOnClickListener(this);

 

        // arena listener

        listener = new BDArenaConnectorListener(this);

 

        // user authentication - put your key in Strings.xml

        BDArenaConnector.initializeWithAppKey(this,

                                                              getResources().getString(R.string.arena_key),                                                                     true);

 

        BDArenaConnector.getInstance().requestAuth();

  

        // enable rotation for 320x53 banner format

        BDArenaConnector.getInstance().

                advEnableRotationForBannerFormat(

                BDArenaAdvBannerFormat.BDArenaAdvBannerFormat320x53

        );

 

}

 

@Override

public void onResume() {

        super.onResume();

 

        // register the listener for callbacks

        BDArenaConnector.getInstance().registerEventsObserver(listener);

 

        // enable rotation for 320x53 banner format

        banner = 

        BDArenaConnector.

                getInstance().

                advGetBannerViewForAdFormat(

                        BDArenaAdvBannerFormat.BDArenaAdvBannerFormat320x53

                );

 

}

 

@Override

public void onPause(){

        super.onPause();

 

        // unregister the listener

        BDArenaConnector.getInstance().unregisterEventsObserver(listener);

}

 

 

Please note that we have also created two Button :

  • The first one (startStopBannerRotationButton) will manage the auto refresh status related to the 320x53 banner display.
  • The second one (getAdClipButton) will set the target View in which the SDK will load and show an ad clip.

Moreover, in the onResume method, we'll place into banner object, as subview, the banner's view.

 

Now we need to add the code for the actions triggered by the two Button:

 

 

@Override

public void onClick(View v) {

        if(v == startStopBannerRotationButton) {

                if(BDArenaConnector.getInstance().advIsBannerRotationActive()) {

 

                        // stop banner rotation

                        BDArenaConnector.getInstance().advBannerStopRotation();

                        bannerContainer.removeAllViews();

 

                        startStopBannerRotationButton.setText(getResources().

                                                                        getString(R.string.button_rotation_start));

                }

                else {

                        // start banner rotation

                        BDArenaConnector.getInstance().advBannerStartRotation();

 

                        startStopBannerRotationButton.setText(getResources().

                                                                        getString(R.string.button_rotation_stop));

                }

        }

        else if(v == getAdClipButton) {

                if(BDArenaConnector.getInstance().isLocalPlayerAuthenticated()) {

 

                        // if you like to customize adClip components appearance,

                        // create a BDArenaAdClipConfigData object

                        BDArenaAdClipConfigData config = new BDArenaAdClipConfigData();

 

                        // for the countdownText property you can use

                        // [remaining], [duration] and [percent] macros...

                        config.setCountdownText(

                                "My app will start in [remaining] seconds ([percent]% played)..."

                        );

                        config.setClickThruAlertTitle("Thanks for the click!");

                        config.setClickThruAlertMessage("Do you want to open the website?");

                        config.setClickThruAlertOpenButtonTitle("Yeah!");

                        config.setClickThruAlertCancelButtonTitle("No, thanks");

 

                        // make call for clip

                        BDArenaConnector.getInstance().advRequestAdClipInView(this,

                                                                                             clipContainer, config);

 

                        getAdClipButton.setEnabled(false);

                }

                else

                        Toast.makeText(this, getResources().getString(R.string.error_auth), 

                                                                        Toast.LENGTH_LONG).show();

        }

}

 


 

Tapping the 'get ad clip' button, the app tells the SDK to retrieve a clip.

When an ad clip is successfully retrieved, the SDK notifies the event by calling

the arenaAdvConnectorClipReadyToPlay method of the BDArenaConnectorListener.

 

If this event occurs, the developer can start the clip playback by calling advPlayAdClipInView

 

 

@Override

public void arenaAdvConnectorClipReadyToPlay(RelativeLayout targetView) {

        BDArenaConnector.getInstance().advPlayAdClipInView(targetView);

}

 

 

In order to be notified when the clip ends, the developer needs to override the

arenaAdvConnectorClipDidFinishPlayback method of BDArenaConnectorListener.

 

  

@Override

public void arenaAdvConnectorClipDidFinishPlayback(

        RelativeLayout targetView,

        int reason) {

                getAdClipButton.setEnabled(true);

}

 

 

For the action getGhostOver we'll set :

 

else if(v == getGhostOverButton) {

 

        if(BDArenaConnector.getInstance().isLocalPlayerAuthenticated()) {

  

                BDArenaConnector.getInstance().advRequestGhostOverAd(this);

                 getGhostOverButton.setEnabled(false);

  

        }

        else{

               //handle error

        }

 }

 

 

Tapping the 'get GhostOver' button, the app tells the SDK to retrieve a GhostOver ad.

When an ad is successfully retrieved, the SDK notifies the event by calling

the arenaConnectorGhostOverReadyToPlay method of the BDArenaConnectorListener interface.

 

If this event occurs, the developer can start the clip playback by calling advPlayGhostOverAd

 

public void arenaAdvConnectorGhostOverReadyToPlay(){

 

       // a GhostOver ad has been found... just play it!

       BDArenaConnector.getInstance().advPlayGhostOverAd();

 

}

 

In order to be notified when the ad ends, the developer needs to override the

arenaConnectorGhostOverDidReachCompletionarenaConnectorGhostOverDidBreak or

arenaConnectorGhostOverPauseOnUnsupportedOrientationTimedout

methods of BDArenaConnectorListener interface.

 

 

NOTE : If the developer needs to support older version of Android API (prior to v. 10), he has to manage programmatically the device orientation changes to prevent Layout reload.

 

In order to achieve that, the developer needs to set orientation|screenSize for the attribute android:configChanges, within the AndroidManifest.xml file, for each Activity that will use the

SDK's ad clip the feature :

 

 

<application

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/AppTheme" >

        <activity

            android:name="com.arenadaemon.helloadclip.MainActivity"

            android:configChanges="orientation|screenSize"

            android:label="@string/app_name" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

       .......

</application>

 

 

Once setup the manifest file, the developer needs to override onConfigurationChanged method

in order to correctly resize the ad clip view :

 

 

@Override

public void onConfigurationChanged(Configuration newConfig) {

        super.onConfigurationChanged(newConfig);

 

        // swap width and height on orientation change (only needed for API <= 10)

        if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {

                if(clipContainerWidth > 0 && clipContainerHeight > 0) {

                        Log.i("ARENA DAEMON", "ORIENTATION CHANGED");

 

                        BDArenaConnector.getInstance().advResizeAdClipInView(

                                                                                        clipContainer,

                                                                                        clipContainerHeight,

                                                                                        clipContainerWidth);

                }

        }

}

 

 

 

The application will look like :

tutorial_advertising_android

 

 


 

 

Sample project

Download the sample project for this tutorial.