LifeStreet Media Android Publisher SDK Integration Guide Version 1.12.0 Copyright 2015 Lifestreet Corporation
Contents Introduction... 3 Downloading the SDK... 3 Choose type of SDK... 3 Adding the LSM SDK to your project... 4 Adding Lifestreet Media Ads to your application... 9 Notifications and Targeting Information... 10 Auto Refresh... 11 Interstitials... 12 Close Button... 12 Custom Events... 12 2
Introduction The purpose of this document is to outline how to integrate the LifeStreet advertising SDK into your application. Use this document if: You want to serve LifeStreet ads in your application You are using the LifeStreet SDK with an SDK mediation service (e.g AdWhirl) You ve talked through integration with your account manager. Downloading the SDK To get the software development kit, please contact your account manager: msupport@lifestreet.com Choose type of SDK We provide two versions of SDK: Binary library Source code These versions share the same functionality both allow you to integrate LifeStreet Media advertisements into your Android applications. We provide a source version for users who want more control or customization of the SDK. For users looking for a turnkey solution, the binary version is available. Both source and binary versions of SDK requires a run-time of Android 2.3 or later (set android:minsdkversion to at least 9 in your AndroidManifest.xml) 3
Adding the LSM SDK to your project 1. Right click on your app project and choose Properties: 4
a). For binary version of the SDK select Java Build Path and Libraries tab, and then click Add External JARs Choose lsmsdk.jar. 5
Then open Order and Export tab and check lsmsdk.jar 6
b). For source version select Java Build Path and Source tab, and then click Add Folder Choose lsmsdk. 2. Modify your AndroidManifest.xml file to include following permissions: <uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.access_network_state"/> <uses-permission android:name="android.permission.read_phone_state"/> <uses-permission android:name="android.permission.write_external_storage"/> Optionally, you can include: <uses-permission android:name="android.permission.access_fine_location"/> Also, declare required LSM activities: <activity android:name="com.lifestreet.android.lsmsdk.ads.interstitialadactivity" android:configchanges="keyboard keyboardhidden orientation screenlayout uimode scre ensize smallestscreensize"/> <activity android:name="com.lifestreet.android.lsmsdk.mraid.mraidinterstitialactivity" android:configchanges="keyboard keyboardhidden orientation screenlayout uimode scre ensize smallestscreensize"/> 7
<activity android:name="com.lifestreet.android.lsmsdk.mraid.videoplayeractivity" android:configchanges="keyboard keyboardhidden orientation screenlayout uimode scre ensize smallestscreensize"/> Here is the example of the configured AndroidManifest.xml file: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.lifestreet.android.lsmsdksample" android:versioncode="1" android:versionname="1.0"> <uses-sdk android:minsdkversion="7" android:targetsdkversion="17"/> <!-- Required permissions --> <uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.access_network_state"/> <uses-permission android:name="android.permission.read_phone_state"/> <uses-permission android:name="android.permission.write_external_storage"/> <!-- Optional permissions --> <uses-permission android:name="android.permission.access_fine_location"/> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme"> <!-- LSM --> <activity android:name="com.lifestreet.android.lsmsdk.ads.interstitialadactivity" android:configchanges="keyboard keyboardhidden orientation screenlayout uimode screensize smallestscreensize"/> <activity android:name="com.lifestreet.android.lsmsdk.mraid.mraidinterstitialactivity" android:configchanges="keyboard keyboardhidden orientation screenlayout uimode screensize smallestscreensize"/> <activity android:name="com.lifestreet.android.lsmsdk.mraid.videoplayeractivity" android:configchanges="keyboard keyboardhidden orientation screenlayout uimode screensize smallestscreensize"/> <!-- Your activities --> <activity android:name="com.lifestreet.android.lsmsdksample.mainactivity" 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> </manifest> 8
Adding Lifestreet Media Ads to your application To place Lifestreet ad views in your application and make ad requests: 1. Add SlotView to your layout: <com.lifestreet.android.lsmsdk.slotview android:id="@+id/slotview" android:layout_width="fill_parent" android:layout_height="53dp" slot_slottag="my_slot_tag" slot_autorefreshenabled="true"/> Alternatively, you can create SlotView dynamically: SlotView slotview = new SlotView(this); slotview.setslottag("my_slot_tag"); slotview.setautorefreshenabled(true); 2. Replace MY_SLOT_TAG with your LSM Slot Tag. Set appropriate view s width and height. 3. Implement SlotListener interface (Optional). slotview.setlistener(this); 4. Add SlotView to the view hierarchy. 5. Call the loadad method to start loading and showing ads. slotview.loadad(); 6. Call the destroy method when you no longer need the SlotView. 7. It is recommended to call pause/resume methods when something obscuring the SlotView (e.g. when you open an parent activity). package com.lifestreet.android.lsmsdksample; import android.app.activity; import android.os.bundle; 9
import com.lifestreet.android.lsmsdk.slotview; public class MainActivity extends Activity { @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); slotview.setslottag("my_slot_tag"); slotview.loadad(); @Override protected void ondestroy() { super.ondestroy(); if (slotview!= null) { slotview.destroy(); @Override protected void onpause() { super.onpause(); if (slotview!= null) { slotview.pause(); @Override protected void onresume() { super.onresume(); if (slotview!= null) { slotview.resume(); Notifications and Targeting Information There are number of notifications that you can listen for and utilize; these are part of the SlotListener interface. public interface SlotListener { public void onfailedtoloadslotview(slotview slotview); 10
public void onreceivead(banneradapter<?> adapter, View view); public void onfailedtoreceivead(banneradapter<?> adapter, View view); public void onpresentscreen(banneradapter<?> adapter, View view); public void ondismissscreen(banneradapter<?> adapter, View view); public void onleaveapplication(banneradapter<?> adapter, View view); public void onclick(banneradapter<?> adapter, View view); public void onclose(banneradapter<?> adapter, View view); public void ondestroycustomeventbanneradapter( BannerAdapter<?> adapter, String name); public void onreceiveinterstitialad( InterstitialAdapter<?> adapter, Object ad); public void onfailedtoreceiveinterstitialad( InterstitialAdapter<?> adapter, Object ad); public void onpresentinterstitialscreen( InterstitialAdapter<?> adapter, Object ad); public void ondismissinterstitialscreen( InterstitialAdapter<?> adapter, Object ad); public void onleaveapplicationinterstitial( InterstitialAdapter<?> adapter, Object ad); public void onclickinterstitialad( InterstitialAdapter<?> adapter, Object ad); public void ondestroycustomeventinterstitialadapter( InterstitialAdapter<?> adapter, String name); Also, you can improve quality of ads and increase your revenue by including targeting information (All fields are optional). SlotTargeting targeting = new SlotTargeting(); targeting.setareacode("925"); targeting.setcity("walnut Creek"); targeting.setgender(slottargeting.gender.male); targeting.setmetro("807"); targeting.setregion("ca"); targeting.setzip("94598"); targeting.setlatitude("37.9136962890625"); targeting.setlongitude("-122.01170349121094"); slotview.settargeting(targeting); Auto Refresh By default the ad slot will be reloaded after a certain period of time. You can disable this behavior by calling the setautorefreshenabled(false) method or control this behavior by pause() and resume() methods: slotview.setautorefreshenabled(false); //... or... slotview.pause(); slotview.resume(); 11
Interstitials The SDK also includes support for interstitial ads. Use the InterstitialSlot class instead of the SlotView to show any ads in full-screen mode. It has the same interface as SlotView class. InterstitialSlot slot = new InterstitialSlot(this); slot.setslottag("my_slot_tag"); slot.loadad(); Close Button Interstitial ads show a close button on the screen by default (at the top-right corner). It is disabled by default for banner ads. You can enable/disable the button with setshowclosebutton(boolean showclosebutton) method. Also, SlotView s listener has a method onclose(banneradapter<?> adapter, View view), which will be called when a close button is clicked. slot.setshowclosebutton(true); Custom Events A custom event is a method that is executed when slot loads an ad with NetworkType set to CUSTOM. This method must be implemented in the object that supplied to slotview.setlistener(object) method. When NetworkType = CUSTOM, the method name will be set in property Function. When a custom event view is no longer needed (e.g. a new ad was loaded) the SDK calls a special method which will allows you to do any necessary cleanup. In the following example, the event has the name customfunction. public void customfunction(banneradapterlistener listener, String data) { DisplayMetrics dm = getresources().getdisplaymetrics(); int width = (int) Utils.convertDipsToPixels(320, dm); int height = (int) Utils.convertDipsToPixels(50, dm); RelativeLayout.LayoutParams layoutparams = new RelativeLayout.LayoutParams(width, height); layoutparams.addrule(relativelayout.center_in_parent); TextView customadview = new TextView(this); customadview.setlayoutparams(layoutparams); customadview.settext("custom View"); customadview.setgravity(gravity.center); customadview.setbackgroundcolor(color.blue); 12
// Do something useful with the "data"... listener.onreceivead(customadview); @Override public void ondestroycustomeventbanneradapter( BannerAdapter<?> adapter, String name) { In order to track clicks from your custom banner ad you need to call special method from the adapter listener: listener.onclick(customadview); 13