如何在android应用程序中实现无需点击按钮的间隙广告?
我已经开发了android应用程序。如何在不点击按钮的情况下向我的android应用程序中添加间隙广告?试试以下方法:如何在android应用程序中实现无需点击按钮的间隙广告?,android,Android,我已经开发了android应用程序。如何在不点击按钮的情况下向我的android应用程序中添加间隙广告?试试以下方法: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //instantiating PublisherInterstitialA
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//instantiating PublisherInterstitialAd
mPublisherInterstitialAd = new PublisherInterstitialAd(this);
//setting ad unit ID.
mPublisherInterstitialAd.setAdUnitId("/6499/example/interstitial");
//loading the ad
mPublisherInterstitialAd.loadAd(new PublisherAdRequest.Builder().build());
//showing the ad
if (mPublisherInterstitialAd.isLoaded()) {
mPublisherInterstitialAd.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
mPublisherInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
@Override
public void onAdClosed() {
// Code to be executed when when the interstitial ad is closed.
// Load the next interstitial.
mPublisherInterstitialAd.loadAd(new PublisherAdRequest.Builder().build());
}
});
}
dependencies {
compile 'com.google.android.gms:play-services-ads:12.0.0'
}
看看这个。