Publisher/Code/Android
Quick Start
1. Serve Ads
Maximize Fill Rate
Reference Links
Flurry Development for Android
Looking for a deep dive? This section is targeted at developers and presents you all the detailed information you need to ensure your implementation of Flurry is technically sound.
Jump to:
Step 1: Serve Ads in fewer than 10 minutes
You can serve interstitial and banner ads very quickly and with little effort using Flurry AppSpot. The following steps are common to all ad types served through Flurry AppSpot.
- Download the Flurry Android SDK. This download will contain both the Flurry Analytics and Flurry AppSpot libraries
- Add the Flurry library code to your project by dragging the FlurryAgent.jar into your project's "libs" folder (NOTE: If you are upgrading the Flurry Android SDK, be sure to remove any existing Flurry jar files before starting.).
- Incorporate the following lines of Flurry code into each Activity of your application (This is required to assure Flurry session tracking captures users’ uninterrupted interaction with the application):
@Override
public void onStart()
{
super.onStart();
FlurryAgent.onStartSession(this, YOUR_API_KEY);
// Your code
}
@Override
public void onStop()
{
super.onStop();
FlurryAgent.onEndSession(this);
//Your code
}
@Override public void onStart() { super.onStart(); FlurryAgent.onStartSession(this, YOUR_API_KEY); // Your code } @Override public void onStop() { super.onStop(); FlurryAgent.onEndSession(this); //Your code }
- Modify your AndroidManifest.xml file:
/** Add permission to access the internet to
* communicate with Flurry servers
*/
<uses-permission android:name="android.permission.INTERNET" />
/** Declare "FlurryFullscreenTakeoverActivity” to show interstitial ads
*/
<activity android:name="com.flurry.android.FlurryFullscreenTakeoverActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode"
android:hardwareAccelerated=”true” >
</activity>
/** Add permission to access the internet to * communicate with Flurry servers */ <uses-permission android:name="android.permission.INTERNET" /> /** Declare "FlurryFullscreenTakeoverActivity” to show interstitial ads */ <activity android:name="com.flurry.android.FlurryFullscreenTakeoverActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode" android:hardwareAccelerated=”true” > </activity>
Note: If you are not supporting high resolution images or mraid ads in your application you may set hardwareAccelerated=false. Hardware acceleration is required for HTML5 inline video playback in ads and is not supported in Android 2.x and earlier versions. If your application is designed for 2.x and earlier exclusively, you may set hardwareAccelerated to false.
2.a. Display Interstitials
This section will show an example of an interstitial integration. Invoke a takeover at a natural pause in your app. For example, when a level is completed, an article is read or a button is pressed.
The basic steps involve fetching an ad, checking if the ad is available, followed by displaying the ad. Interstitials ad serving flow is best implemented with the fetchAd and displayAd methods and the FlurryAdListener interface.
/**
* We recommend that you use the asynchronous ad serving flow, implemented
* with the methods fetchAd, displayAd, and the interface FlurryAdListener
*/
import com.flurry.android.FlurryAds;
import com.flurry.android.FlurryAdSize;
import com.flurry.android.FlurryAgent;
import com.flurry.android.FlurryAdListener;
public class Example extends Activity implements FlurryAdListener {
FrameLayout mBanner;
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
mBanner = new FrameLayout(this);
// allow us to get callbacks for ad events
FlurryAds.setAdListener(this);
}
@Override
public void onStart() {
super.onStart();
FlurryAgent.onStartSession(this, mApiKey);
// fetch and prepare ad for this ad space. won’t render one yet
FlurryAds.fetchAd(this, ”INTERSTITIAL_MAIN_VIEW”, mBanner, FlurryAdSize.FULLSCREEN);
}
public void spaceDidReceiveAd(String adSpace) {
// called when the ad has been prepared, ad can be displayed:
FlurryAds.displayAd(this, adSpace, mBanner);
}
@Override
public void onStop() {
super.onStop();
FlurryAgent.onEndSession(this);
}
}
/** * We recommend that you use the asynchronous ad serving flow, implemented * with the methods fetchAd, displayAd, and the interface FlurryAdListener */ import com.flurry.android.FlurryAds; import com.flurry.android.FlurryAdSize; import com.flurry.android.FlurryAgent; import com.flurry.android.FlurryAdListener; public class Example extends Activity implements FlurryAdListener { FrameLayout mBanner; @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); mBanner = new FrameLayout(this); // allow us to get callbacks for ad events FlurryAds.setAdListener(this); } @Override public void onStart() { super.onStart(); FlurryAgent.onStartSession(this, mApiKey); // fetch and prepare ad for this ad space. won’t render one yet FlurryAds.fetchAd(this, ”INTERSTITIAL_MAIN_VIEW”, mBanner, FlurryAdSize.FULLSCREEN); } public void spaceDidReceiveAd(String adSpace) { // called when the ad has been prepared, ad can be displayed: FlurryAds.displayAd(this, adSpace, mBanner); } @Override public void onStop() { super.onStop(); FlurryAgent.onEndSession(this); } }
You can register FlurryAdListener to be notified of events in the ad's lifecycle. The interstitials can expect the following delegates to fire:
- spaceDidReceiveAd(String adSpaceName)
- boolean shouldDisplayAd(String adSpaceName, FlurryAdType type)
You can determine whether to display the retrieved ad or not - onAdClosed(String adSpaceName)
- onApplicationExit(String adSpaceName)
This listener results from user's action on the banner's takeover, the user is taken to the browser or the app store - spaceDidFailToReceiveAd(String adSpaceName)
Fires In case of a failure to retrieve ads, you can fetch another ad. - onAdClicked(String adSpaceName)
Clicking on a banner, opens up the ad in a takeover, in this llistener perform steps to pause the app activity. After the click, the banner ad will display the ad takeover with the ad image or video. After the takeover is closed, the banner ad space will keep being refreshed. - onAdOpened(String adSpaceName)
- onVideoCompleted(String adSpace)
2.b Serve Banner Ads
The following section will illustrate the method to show banners within your app.
Banners can be retrieved asynchronously as the Activity is started.
/**
* We recommend that you use the asynchronous ad serving flow, implemented
* with the methods fetchAd, displayAd, and the interface FlurryAdListener
*/
import com.flurry.android.FlurryAds;
import com.flurry.android.FlurryAdSize;
import com.flurry.android.FlurryAgent;
import com.flurry.android.FlurryAdListener;
public class Example extends Activity implements FlurryAdListener {
FrameLayout mBanner;
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
mBanner = new FrameLayout(this);
// allow us to get callbacks for ad events
FlurryAds.setAdListener(this);
}
@Override
public void onStart() {
super.onStart();
FlurryAgent.onStartSession(this, mApiKey);
// fetch and prepare ad for this ad space. won’t render one yet
FlurryAds.fetchAd(this, ”BANNER_MAIN_VIEW”, mBanner, FlurryAdSize.BANNER_BOTTOM);
}
public void spaceDidReceiveAd(String adSpace) {
// called when the ad has been prepared, ad can be displayed:
FlurryAds.displayAd(this, adSpace, mBanner);
}
@Override
public void onStop() {
super.onStop();
FlurryAgent.onEndSession(this);
}
}
/** * We recommend that you use the asynchronous ad serving flow, implemented * with the methods fetchAd, displayAd, and the interface FlurryAdListener */ import com.flurry.android.FlurryAds; import com.flurry.android.FlurryAdSize; import com.flurry.android.FlurryAgent; import com.flurry.android.FlurryAdListener; public class Example extends Activity implements FlurryAdListener { FrameLayout mBanner; @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); mBanner = new FrameLayout(this); // allow us to get callbacks for ad events FlurryAds.setAdListener(this); } @Override public void onStart() { super.onStart(); FlurryAgent.onStartSession(this, mApiKey); // fetch and prepare ad for this ad space. won’t render one yet FlurryAds.fetchAd(this, ”BANNER_MAIN_VIEW”, mBanner, FlurryAdSize.BANNER_BOTTOM); } public void spaceDidReceiveAd(String adSpace) { // called when the ad has been prepared, ad can be displayed: FlurryAds.displayAd(this, adSpace, mBanner); } @Override public void onStop() { super.onStop(); FlurryAgent.onEndSession(this); } }
Once displayed, the banners will be refreshed every 30 seconds until the FlurryAds.removeAd is called. The default 30 seconds refresh can be changed on the dev portal (see Ad refresh rate in the Advanced settings ).
Similarly to the above sample of an interstitial ad space, you can register FlurryAdListener. The banners can expect the following delegates to fire:
- spaceDidReceiveAd(String adSpaceName)
- boolean shouldDisplayAd(String adSpaceName, FlurryAdType type)
You can determine whether to display the retrieved ad or not - spaceDidFailToReceiveAd(String adSpaceName)
Fires In case of a failure to retrieve ads, you can fetch another ad. - onAdClicked(String adSpaceName)
Clicking on a banner, opens up the ad in a takeover, in this llistener perform steps to pause the app activity. After the click, the banner ad will display the ad takeover with the ad image or video. After the takeover is closed, the banner ad space will keep being refreshed.
- onVideoCompleted(String adSpace)


