Created
October 18, 2014 19:22
-
-
Save ziedrebhi/03462287db592cc05e20 to your computer and use it in GitHub Desktop.
Integrate Admob pub Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Tuto Admob Android | |
* @author Zied Rebhi | |
* http://www.tutozone.info | |
*/ | |
public class MainActivity extends Activity { | |
private InterstitialAd interstitial; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// Prepare the Interstitial Ad | |
interstitial = new InterstitialAd(MainActivity.this); | |
// Insert the Ad Unit ID | |
interstitial.setAdUnitId("ca-app-pub-13456789"); | |
//Locate the Banner Ad in activity_main.xml | |
AdView adView = (AdView) this.findViewById(R.id.adView); | |
// Request for Ads | |
AdRequest adRequest = new AdRequest.Builder() | |
// Add a test device to show Test Ads | |
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) | |
.addTestDevice("E3476884AF84FA254EC41B585B555338") | |
.build(); | |
// Load ads into Banner Ads | |
adView.loadAd(adRequest); | |
// Load ads into Interstitial Ads | |
interstitial.loadAd(adRequest); | |
// Prepare an Interstitial Ad Listener | |
interstitial.setAdListener(new AdListener() { | |
public void onAdLoaded() { | |
// Call displayInterstitial() function | |
displayInterstitial(); | |
} | |
}); | |
} | |
public void displayInterstitial() { | |
// If Ads are loaded, show Interstitial else show nothing. | |
if (interstitial.isLoaded()) { | |
interstitial.show(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment