我第一次使用adsmob sdk。我不知道如何加载广告,因为我想加载。这是我的代码:
mInterstitialAd = new InterstitialAd(this);
// set the ad unit ID
InterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
adRequest = new AdRequest.Builder().build();
// Load ads into Interstitial Ads
mInterstitialAd.loadAd(adRequest);
mInterstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
showInterstitial();
}
});
}
private void showInterstitial() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
答案 0 :(得分:1)
如果您使用计时器弹出插页式广告,您的admob帐户将被禁止。
如果您想在活动结束后显示插页式广告,请尝试以下操作: 例如,如果您正在使用webview,并希望在页面加载后显示插页式广告:
Public class ads extends AppCompatActivity {
InterstitialAd mInterstitialAd;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//This is where you initialize ads
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-xxxxxxxxxx");
//This function request new Interstitial.
requestNewInterstitial();
myWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int newProgress) {
progress.setProgress(newProgress);
progress.setVisibility(View.VISIBLE);
if (newProgress == 100) {
progress.setVisibility(View.GONE);
// Interstitialads is shown after calling mInterstitial.show()
mInterstitialAd.show();
}
}
}
);
}
//This function initializes new ads.
private void requestNewInterstitial() {
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
}
}