Beruflich Dokumente
Kultur Dokumente
AndroidSDKInstructions
SDKversion4.0.0
Updated:05/19/2014
WelcometoFlurryAdvertising!
ThisREADMEcontains:
1.Introduction
2.BasicIntegration
3.AdditionalAdControls(Optional)
4.EnablingAdNetworkMediation(Optional)
5.RequestConfiguration(Optional)
6.ImplementingAdListener(Optional)
1.Introduction
FlurryAdvertisingisaflexibleadservingsolutionthatallowsyoutoeasilymanagethecomplete
monetizationofyourmobileapplications.ThroughintegrationwithFlurryAnalyticsandvariousmobilead
networks,publisherscaneasilygeneratethemaximumvaluefromadcampaigns.BothFFA(FlurryFor
Advertisers)andFFP(FlurryForPublishersdirectandcustomnetwork)adcampaignsarecreatedand
managedinthesameinterface.
WithFFPyouwillbeableto:
1. Defineyourinventory
2. Trafficyouradcampaigns
3. Track&optimizeyourperformance
TheFlurrySDKcontainsalltheexistingFlurryAnalyticsfunctionalityaswellasthenewAdvertising
functionality.Itisdesignedtobeaseasyaspossiblewithabasicsetupcompletedinunder5minutes.
TheseinstructionsassumethatyouhavealreadyintegratedFlurryAnalyticsintoyourapplication.Ifyou
havenotdoneso,pleaserefertoAnalyticsREADMEtogetstarted.
ForadspacesetupandmoreinformationonFlurryadvertising,pleasevisit
http://support.flurry.com/index.php?title=Guides/s/Publishers
Pleasenote,itisrequiredthatyoucreateadspacesbeforeretrievingads.Adspacescanbecreatedon
theFlurryDeveloperPortalorintheapplicationcode.IfAdspacesarecreatedinthecode,theywillappear
inthedevportaldesignatedasDeterminedbySDKintheAdspacesetuppage.
FlurryAdvertisingusestheAndroidAdvertisingIDprovidedbyGooglePlayServicesandwillcheckforand
respecttheuser'sadtrackingpreference.Formoreinformation,pleasevisit
https://developer.android.com/google/playservices/id.html
2.BasicIntegration
FlurryAdsrequiresminimumAndroidAPIlevel10.TointegrateFlurryAdvertisingintoyourAndroid
application,justcompletetwosteps:
Step1.Includetheappropriatejar
FlurryAdsworkontopofFlurryanalytics.AddFlurryAds_4.0.0.jarfile(inadditiontothethe
FlurryAnalytics_4.0.0.jarand)toyourclasspath.
UsingAndroidStudio:
1. AddFlurryAnalytics 4.0.0.jarandFlurryAds_4.0.0.jartoyourproject'slibsfolder.
2. NavigatetoFile>ProjectStructure>Module>Dependencies.Clickthe+buttoninthebottomof
theProjectStructurepopuptoadddependencies.SelectFiledependencyandadd
libs/FlurryAnalytics 4.0.0.jarandlibs/FlurryAds_4.0.0.jarand.
3. AddGooglePlayServiceslibrary.Pleasefollowinstructionsat
http://developer.android.com/google/playservices/setup.html#Setup
4. Addv4supportlibrary(orgreater).Pleasefollowinstructionsat
https://developer.android.com/tools/supportlibrary/setup.html#addlibrary
UsingEclipse:
1. AddFlurryAnalytics 4.0.0.jarandFlurryAds_4.0.0.jartoyourprojectslibsfolder.Rightclickoneach
JARfileandselectBuildPath>AddtoBuildPath.
2. AddGooglePlayServicelibrary.Pleasefollowinstructionsat
http://developer.android.com/google/playservices/setup.html#Setup
3. Addv4SupportLibrary(orgreater).Pleasefollowinstructionsat
https://developer.android.com/tools/supportlibrary/setup.html#addlibrary.
Step2.DeclareourActivityinyourmanifest
DeclaretheActivityFlurryFullscreenTakeoverActivityinyourAndroidManifest.xmlfile:
<activity
android:name="com.flurry.android.FlurryFullscreenTakeoverActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|
uiMode|screenSize|smallestScreenSize"
</activity>
Thisisrequiredtoshowinterstitialads.
OptionalPermission(HighlyRecommended):
android.permission.WRITE_EXTERNAL_STORAGE
Externalstorageisusedforprecachingfeaturesifavailable.
Step3.Requestinganad
InordertoserveadspleaseusemethodsfetchAd,displayAdandtheinterfaceFlurryAdListener.
Followingissampleintegrationcodetoservebannerad.Toseeintegrationofinterstitialadandfor
additionalinformation,pleasevisitflurryssupportsiteat
http://support.flurry.com/index.php?title=Guides/f/Publishers/Code/Interstitials/Android.
publicclassExampleextendsActivityimplementsFlurryAdListener{
RelativeLayoutmBanner
publicvoidonCreate(Bundlebundle){
super.onCreate(bundle)
setContentView(R.layout.example)
mBanner=(RelativeLayout)findViewById(R.id.banner)
//allowustogetcallbacksforadevents
FlurryAds.setAdListener(this)
}
publicvoidonStart(){
super.onStart()
FlurryAgent.onStartSession(this,mApiKey)
//fetchandprepareadforthisadspace.wontrenderoneyet
FlurryAds.fetchAd(this,mAdSpaceName,mBanner,
FlurryAdSize.BANNER_BOTTOM)
}
publicvoidonStop(){
super.onStop()
FlurryAgent.onEndSession(this)
}
publicvoidspaceDidReceiveAd(StringadSpace){
//calledwhentheadhasbeenprepared,adcanbedisplayed:
FlurryAds.displayAd(this,mAdSpaceName,mBanner)
}
}
Note:pleaseseeAnalyticsREADMEfordetailsonFlurryAgent.onStartSession()
HerearethedetailsontheparameterstofetchAdanddisplayAd:
ContextcontextWeadviseusingthecurrentActivity.
StringadSpaceUniquenameofyouradplacement,maydefinedontheFlurrywebsite,but
doesnothavetobe
ViewGroupviewSpaceViewGroupinsidetheContextthatyouwanttheadtoresidein.We
suggestusingaRelativeLayout
FlurryAdSizesizeThesizeofadtofetch,ifthishasnotbeensetontheserverforthisad
space
NotethatthesameadcallisusedforalladformatsandsizesincludingBanner,TakeoverandCustomad
formats.
Inordertospecifytheformatandsize,pleasevisitFlurrysdeveloperportalat
https://dev.flurry.com/FFPSetupAdSpaces.do
3.AdditionalAdControls(Optional)
Requestadsaheadoftime
AddthefollowinglinetoyourappafterthecalltoFlurryAgent.onStartSession()inyourmain
ActivitysonStartmethod.ThismethodwillmakeanasynchronousadrequesttotheFlurryadserver,
whichwillrespondwithadsforadspacesthathaveprecachingenabled.Thisonlyneedstobecalledonce.
PleaseseetheAnalyticsREADMEfordetailsonFlurryAgent.onStartSession().
FlurryAds.initializeAds(Contextcontext)
Pleasenote:initializeAdshasbeendeprecatedin4.0.0.
Checkiftheadisready
Thefollowingmethodcallreturnsabooleanvaluetoletyouknowifanadhasbeenfetchedandpreparedfor
display.Thismethodworksbestaftercallingfetch(),andthenatruevalueindicatesthatyoucanmakea
display()calltodisplaythead.
FlurryAds.isAdReady(StringadSpace)
Removinganad
Flurrymanagesthelifecycleoftheadsitdisplays,however,youcanexercisefinercontroloverdisplayby
choosingwhentoaddandremovetheadsfromyourapp.Toremoveanadjustcall
FlurryAds.removeAd(Contextcontext,StringadSpace,ViewGroupviewGroup)
Theparametersareasfollows:
ContextcontextContextyouwanttheadtoresidewithin.WeadviseusingthecurrentActivity.
StringadSpaceUniquenameofyouradplacement,maydefinedontheFlurrywebsite,butdoes
nothavetobe
ViewGroupviewGroupViewGroupinsidetheContextthatyouwanttheadtoresidein
VideoAds
Startingwithversion4.0.0,FlurryAndroidSDKsupportsprecachingofthevideoadsforenhanceduser
experienceandbettercompletionrate.PrecachingisdoneforvideoadsservedbyFlurrymarketplaceand
byFlurryFFA.
Sinceversion4.0.0,FlurrySDKsupportsdisplayingVASTLinear(includingVASTWrapper)adsfromFlurry
marketplace.
Thesefeaturesaresupportedautomaticallywithoutanyadditionalintegration.
4.EnablingAdNetworkMediation(Optional)
OnceyouhaveyourAdSpacessetup,youwillhavetheoptionofselecting3rdpartyadnetworkstoserve
adsintoyourAdSpacesusingtheFlurrywebsite(inadditiontoFFA,FFPandyourownads).Youcan
changewhichadnetworksserveadsatanytimeontheFlurrywebsite,butinordertoenablethemyou
needtoaddtheadnetworkSDKsintoyourapplicationandconfigurethem.Thelistofcurrentlysupported
AdNetworkscontains:
GoogleMobileAdsincludedautomaticallyinGooglePlayServicesSDK
MillennialSDKVersion5.1.0
InMobiSDKVersion4.1.0
ToimplementanAdNetworkyoumustperformthefollowingsteps:
1. IncludetheAdNetworkAndroidSDKwithyourappandaddittothebuildpath.Followthe
instructionsfromtheAdnetworkonhowtocompletethisstep.
2. CreatetheproperactivityandmetadatatagsinAndroidManifest.xml
a. thefirstmetadatataginstructstheSDKabouthowtofindtheAPI_KEY
b. thesecondmetadatataginstructstheSDKwhethertorequesttestads
3. AddyourAPI_KEYinstrings.xml
HereistheexampleofimplementingtheGoogleMobileAdsSDK:
AndroidManifest.xml
<activityandroid:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|
uiMode|screenSize|smallestScreenSize"/>
<metadataandroid:name="com.flurry.gms.ads.MY_AD_UNIT_ID"
android:value="@string/ffp_gms_apikey"/>
<metadataandroid:name="com.flurry.gms.ads.MYTEST_AD_DEVICE_ID"
android:value="@string/ffp_gms_testdevicekey"/>
<metadataandroid:name="com.flurry.gms.ads.test"
android:value="true"/>
strings.xml
<stringname="ffp_gms_apikey">YOUR_API_KEY</string>
<stringname="ffp_gms_testdevicekey">(adddeviceidthatshowsin
logcat</string>
Note:admob.testvalueneedstobesettotrueabove.Thiswillenableadmob
testadstoshowupintheemulatorandonadevice.
HereisanexampleofimplementingtheMillennialSDK:
AndroidManifest.xml
<activityandroid:name="com.millennialmedia.android.MMActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|
uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
<metadata
android:name="com.flurry.millennial.MYAPID"
android:value="@string/ffp_millennial_apikey"/>
<metadata
android:name="com.flurry.millennial.MYAPIDINTERSTITIAL"
android:value="@string/ffp_millennial_apikey_interstitial"/>
<metadata
android:name="com.flurry.millennial.MYAPIDRECTANGLE"
android:value="@string/ffp_millennial_apikey_rectangle"/>
strings.xml
<stringname="ffp_millennial_apikey">YOUR_MILLENNIAL_API_KEY</string>
<string
name="ffp_millennial_apikey_interstitial">YOUR_MILLENNIAL_INTERSTITIAL_API_KEY
</string>
<string
name="ffp_millennial_apikey_rectangle">YOUR_MILLENNIAL_INTERSTITIAL_API_RECTAN
GLE</string>
HereisanexampleofimplementingtheInmobiSDK:
AndroidManifest.xml
<activityandroid:name="com.inmobi.androidsdk.IMBrowserActivity
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|
uiMode|screenSize|smallestScreenSize"
android:hardwareAccelerated="true"/>
<metadataandroid:name="com.flurry.imobi.APP_ID"
android:value="@string/ffp_inmobi_apikey"/>
strings.xml
<stringname="ffp_inmobi_apikey">YOUR_INMOBI_API_KEY</string>
5.RequestConfiguration(Optional)
Thereareanumberofconfigurationparametersthatyoucanusetomodifythebehaviorofyouradspaces.
Option1.SetLocation
Callthismethodtosetthecurrentlocation(usedwithgeographicaltargeting)
FlurryAds.setLocation(floatlatitude,floatlongitude)
Option2.UserCookies
Addacalltoidentifyanyuserspecificinformationyouwantassociatedwiththeadrequest:
FlurryAds.setUserCookies(Map<String,String>cookies)
Toremoveanyusercookiescall:
FlurryAds.clearUserCookies()
Option3.KeywordTargeting
Addacalltospecifykeywordstobeusedwhentargetingads:
FlurryAds.setTargetingKeywords(Map<String,String>keywords)
6.ImplementingAdListener
TobenotifiedofcertaineventsduringthefulllifecycleoftheAd,youshallimplementtheFlurryAdListener
interfaceandthencallthesetAdListenermethodtoattachyourimplementationofFlurryAdListenertothe
FlurrySDK.Youwillneedtoimplementthefollowingcallbackmethods:
onAdClicked(StringadSpace)
Thismethodwillbecalledwhentheuserhasclickedonthead.
onAdClosed(StringadSpace)
ThismethodwillbecalledwhentheuserdismissesthecurrentAdfortheprovidedAd
Spacename.Thisisapplicableforfullscreenadsonly.
onAdOpened(StringadSpace)
Thismethodwillbecalledwhentheuserhasopenedthead.
onApplicationExit(StringadSpace)
Thismethodwillbecalledwhentheuserisleavingtheapplicationafterfollowingevents
associatedwiththecurrentAdintheprovidedAdSpacename.
onRendered(StringadSpace)
Thismethodwillbecalledwhenadissuccessfullyrendered.
onRenderFailed(StringadSpace)
Thismethodwillbecalledwhenadwasfetchedfromtheadnetworkbutwasnot
successfullyrendered.
shouldDisplayAd(StringadSpace,FlurryAdTypetype)
ThismethodwillbecalledifthereisanadavailabletodisplayforthatadSpace.Return
valueistrueiftheadshouldbedisplayedfalseifnot.
spaceDidReceiveAd(StringmyAdSpaceName)
Thismethodwillbecalledwhentheadhasbeenreceivedfromtheserver
spaceDidFailToReceiveAd(StringmyAdSpaceName)
Thismethodwillbecalledwhentheadrequestwasmadebutnoadswereretrieved.
onVideoCompleted(StringadSpace)
Incasetheadservedisavideoclipandadspaceismarkedasclientsiderewarded,this
methodindicatestheusercompletedwatchingthevideo.
Exampleusage:
publicclassMyAdListenerimplementsFlurryAdListener{
@Override
publicbooleanshouldDisplayAd(StringmyAdSpaceName,FlurryAdTypetype)
{
returntrue
}
@Override
publicvoidonAdClosed(StringadSpaceName)
{
//Handletheuserclosingthead
@Override
publicvoidonApplicationExit(StringadSpaceName)
{
//Handletheuserexitingtheapplication
}
@Override
publicvoidonRendered(StringadSpaceName)
{
//Handlerendered
}
@Override
publicvoidonRenderFailed(StringadSpaceName)
{
//Handlerenderfailed
}
@Override
publicvoidspaceDidReceiveAd(StringadSpaceName)
{
//Handletheadspacereceivingthead
}
@Override
publicvoidspaceDidFailToReceiveAd(StringadSpaceName)
{
//Handletheadspacenotreceivingthead
}
@Override
publicvoidonAdClicked(StringadSpaceName)
{
//Handletheuserclickingthead
}
@Override
publicvoidonAdOpened(StringadSpaceName)
{
//Handletheuseropeningthead
}
@Override
publicvoidonVideoCompleted(StringadSpace)
{
//calledwhenauserfinisheswatchingavideo
}
}
FlurryAdListenermyAdListener=newMyAdListener()//Createaninstance
FlurryAds.setAdListener(myAdListener) //Registerthelistener
7.UsingProGuard(Optional)
IfyouplantorunProGuardonyourAPKbeforereleasingyourapp,youwillneedtoaddthefollowingtoyour
proguard.cfgfile:
keepclasscom.flurry.**{*}
dontwarncom.flurry.**
keepattributes*Annotation*,EnclosingMethod
keepclasseswithmembersclass*{
public<init>(android.content.Context,android.util.AttributeSet,int)
}
#GooglePlayServiceslibrary
keepclass*extendsjava.util.ListResourceBundle{
protectedObject[][]getContents()
}
keeppublicclass
com.google.android.gms.common.internal.safeparcel.SafeParcelable{
publicstaticfinal***NULL
}
keepnames@com.google.android.gms.common.annotation.KeepNameclass*
keepclassmembernamesclass*{
@com.google.android.gms.common.annotation.KeepName*
}
keepnamesclass*implementsandroid.os.Parcelable{
publicstaticfinal**CREATOR
}
IfyouareusingtheGoogleMobileAdsSDK,addthefollowing:
#PreserveGMSadsclasses
keepclasscom.google.android.gms.ads.**{*}
dontwarncom.google.android.gms.ads.**
IfyouareusingtheInMobiSDK,addthefollowing:
#PreserveInMobiAdsclasses
keepclasscom.inmobi.**{*}
dontwarncom.inmobi.**
IfyouareusingtheMillennialMediaSDK,addthefollowing:
#PreserveMillennialAdsclasses
keepclasscom.millennialmedia.**{*}
dontwarncom.millennialmedia.**