[英]How to show interstitial ads?
如何显示插页式广告?
@Override
protected void onCreate(Bundle savedInstanceState) {
//Log.v("SDL", "onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-2188258702xxxxxxxxxxx");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("XXXXXXXXXXXXX")
.build();
interstitial.loadAd(adRequest);
// So we can call stuff from static callbacks
mSingleton = this;
// Set up the surface
mEGLSurface = EGL10.EGL_NO_SURFACE;
mSurface = new SDLSurface(getApplication());
mLayout = new AbsoluteLayout(this);
mLayout.addView(mSurface);
setContentView(mLayout);
}
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
我将sdl2用于android,并且尝试在我的应用中展示插页式广告,但没有显示。 如果我对此行发表评论setContentView(mLayout); 并调用displayinterstitial()都可以正常工作,但所有sdl本机内容除外(屏幕为黑色):-)
问题是如何在Android上使用sdl制作插页式广告?
完整的SDLActivity代码在这里: http ://pastebin.com/DsRRtRS5
似乎您没有提到过:displayInterstitial(),在onCreate()方法中的任何位置,您确定代码执行到达了displayInterstitial()方法吗?
此外,在广告完全加载并可以显示之后,您会在某些地方返回代码。 如:
@Override
public void onReceiveAd(Ad ad) {
Log.d("OK", "Received ad");
if (ad == interstitial) {
interstitial.show();
}
}
public class MainActivity extends Activity {
private InterstitialAd interstitial;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from activity_main.xml
setContentView(R.layout.activity_main);
// Prepare the Interstitial Ad
interstitial = new InterstitialAd(MainActivity.this);
// Insert the Ad Unit ID
interstitial.setAdUnitId("ca-app-pub-6641284216335957/7211421024");
//Locate the Banner Ad in activity_main.xml
AdView adView = (AdView) this.findViewById(R.id.adView);
// Request for Ads
AdRequest adRequest = new AdRequest.Builder()
// Add a test device to show Test Ads
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("")
.build();
// Load ads into Banner Ads
adView.loadAd(adRequest);
// Load ads into Interstitial Ads
interstitial.loadAd(adRequest);
// Prepare an Interstitial Ad Listener
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});
}
public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
if (interstitial.isLoaded()) {
interstitial.show();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.