Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 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~xxxxxxxxxx");
  27.         mInterstitialAd = new InterstitialAd(this);
  28.         mInterstitialAd.setAdUnitId("ca-app-pub-4887098256796636/xxxxxxxxxx");
  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.      
  34.  
  35.  
  36.         myButton.setOnClickListener(new View.OnClickListener() {
  37.  
  38.             public void onClick(View v) {
  39.                 if (mInterstitialAd.isLoaded()) {
  40.                     mInterstitialAd.show();
  41.                    
  42.                 } else {
  43.                     Log.d("TAG", "The interstitial wasn't loaded yet.");
  44.                    
  45.                 }
  46.             }
  47.         });
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement