Skip to content

Instantly share code, notes, and snippets.

@Bisera
Last active December 17, 2015 23:29
Show Gist options
  • Save Bisera/5689388 to your computer and use it in GitHub Desktop.
Save Bisera/5689388 to your computer and use it in GitHub Desktop.
import com.flurry.android.FlurryAds;
import com.flurry.android.FlurryAdSize;
import com.flurry.android.FlurryAgent;
import com.flurry.android.FlurryAdListener;
public class InterstitialAdsActivity extends Activity implements FlurryAdListener {
FrameLayout adLayout;
// the adSpaceName refers to the ad space configured on dev.flurry.com under Publishers tab
// under left-hand nav Inventory / Ad Spaces
String adSpaceName = "Takeover";
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
adLayout = new FrameLayout(this);
Button fetchAd = (Button)findViewById(R.id.fetch);
fetchAd.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// fetch and prepare ad for this ad space. won’t render one yet
if (!FlurryAds.isAdReady(adSpace))
FlurryAds.fetchAd(mContext, adSpaceName, adLayout, FlurryAdSize.FULLSCREEN);
}
});
}
@Override
public void onStart() {
super.onStart();
FlurryAgent.onStartSession(this, mApiKey);
// get callbacks for ad events
FlurryAds.setAdListener(this);
}
@Override
public void spaceDidReceiveAd(String adSpace) {
// called when the ad has been prepared, ad can be displayed:
FlurryAds.displayAd(this, adSpace, adLayout);
// instead of displaying the ad here, you can check
// FlurryAds.isAdReady(adSpace)
// and display the ad when transitioning out of the activity.
}
@Override
public boolean shouldDisplayAd(String adSpace, FlurryAdType arg1) {
//verify this method returns true to display the fetched ad
return true;
}
@Override
public void onStop() {
super.onStop();
// remove the adSpace and the listener
FlurryAds.removeAd(this, adSpaceName, adLayout);
FlurryAgent.onEndSession(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment