Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.57 KB | None | 0 0
  1. package com.example.habib.tambah_kurang;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.TextView;
  9. import com.google.android.gms.ads.AdListener;
  10. import com.google.android.gms.ads.MobileAds;
  11. import com.google.android.gms.ads.AdRequest;
  12. import com.google.android.gms.ads.InterstitialAd;
  13.  
  14.  
  15. public class MainActivity extends AppCompatActivity {
  16.  
  17.     public InterstitialAd mInterstitialAd;
  18.     public Button myButton ;
  19.     public TextView ads_text ;
  20.  
  21.     @Override
  22.     protected void onCreate(Bundle savedInstanceState) {
  23.         super.onCreate(savedInstanceState);
  24.         setContentView(R.layout.activity_main);
  25.  
  26.         MobileAds.initialize(this, "ca-app-pub-4887098256796636~6920828936");
  27.         mInterstitialAd = new InterstitialAd(this);
  28.         mInterstitialAd.setAdUnitId("ca-app-pub-4887098256796636/1594025220");
  29.         mInterstitialAd.loadAd(new AdRequest.Builder().build());
  30.         myButton = (Button)findViewById(R.id.Ads);
  31.         ads_text = (TextView)findViewById(R.id.Ads_text) ;
  32.  
  33.         mInterstitialAd.setAdListener(new AdListener() {
  34.             @Override
  35.             public void onAdLoaded() {
  36.                 // Code to be executed when an ad finishes loading.
  37.                 if (mInterstitialAd.isLoaded()) {
  38.                     mInterstitialAd.show();
  39.                 } else {
  40.                     Log.d("TAG", "The interstitial wasn't loaded yet.");
  41.                 }
  42.             }
  43.  
  44.             @Override
  45.             public void onAdFailedToLoad(int errorCode) {
  46.                 // Code to be executed when an ad request fails.
  47.             }
  48.  
  49.             @Override
  50.             public void onAdOpened() {
  51.                 // Code to be executed when the ad is displayed.
  52.             }
  53.  
  54.             @Override
  55.             public void onAdLeftApplication() {
  56.                 // Code to be executed when the user has left the app.
  57.             }
  58.  
  59.             @Override
  60.             public void onAdClosed() {
  61.                 // Code to be executed when when the interstitial ad is closed.
  62.             }
  63.         });
  64.  
  65.  
  66.         myButton.setOnClickListener(new View.OnClickListener() {
  67.  
  68.             public void onClick(View v) {
  69.                 if (mInterstitialAd.isLoaded()) {
  70.                     mInterstitialAd.show();
  71.                    
  72.                 } else {
  73.                     Log.d("TAG", "The interstitial wasn't loaded yet.");
  74.                    
  75.                 }
  76.             }
  77.         });
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement