如何在每次按下按钮时显示Admob非页内广告?

时间:2017-07-01 18:20:47

标签: java android android-studio admob interstitial

在Android开发方面,我是一个BEGINNER。这是我的第一个申请。我想知道每次按下按钮时如何显示Admob插页式广告。这是我的代码:

package hamza.guideforx.com.guideforx;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

public void onButtonClick(View v) {

    if (v.getId() == R.id.Bdisplay) ;

    {
        Intent i =new Intent(MainActivity.this, Display.class);
        startActivity(i);
    }

}

      public void onButton1(View v1) {
          if (v1.getId() == R.id.Button1) ;
           {
            Intent o =new Intent(MainActivity.this, Page.class);
            startActivity(o);
           }

       }


public void onButton2(View v2) {
    if (v2.getId() == R.id.Button2) ;
    {
        Intent q =new Intent(MainActivity.this, Page2.class);
        startActivity(q);
    }

   }
}

先谢谢。

1 个答案:

答案 0 :(得分:0)

试试这个 -

 OkHttpClient client = // ...
 Picasso picasso = new Picasso.Builder(context)
     .downloader(new OkHttp3Downloader(client))
     .build()

点击按钮 -

mInterstitialAd = new InterstitialAd(this);

    // set the ad unit ID
    mInterstitialAd.setAdUnitId(InterstitialAd_ID);

    AdRequest adRequest = new AdRequest.Builder().build();

    // Load ads into Interstitial Ads
    mInterstitialAd.loadAd(adRequest);


    mInterstitialAd.setAdListener(new AdListener() {

        @Override
        public void onAdClosed() {
            super.onAdClosed();
        }

        @Override
        public void onAdFailedToLoad(int i) {
            super.onAdFailedToLoad(i);    
        }

        @Override
        public void onAdLeftApplication() {
            super.onAdLeftApplication();    
        }

        @Override
        public void onAdOpened() {
            super.onAdOpened();
        }

        public void onAdLoaded() {
            if (mInterstitialAd.isLoaded()) {
            }   
        }
    });