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 for android,并尝试在我的应用中显示插页式广告,但它没有显示.如果我评论这一行 setContentView(mLayout);并调用 displayinterstitial() 一切正常,除了所有 sdl 原生内容(屏幕为黑色):-)
I use sdl2 for android, and I trying to show interstitial ads in my app, but it's doesn't show. If I comment this line setContentView(mLayout); and call displayinterstitial() all works fine, except all sdl native content(screen is black):-)
问题是如何在 android 上使用 sdl 制作插页式广告?
And question is How to make work interstitial ads with sdl on android?
完整的 SDLActivity 代码在这里:http://pastebin.com/DsRRtRS5
Full SDLActivity code here: http://pastebin.com/DsRRtRS5
推荐答案
你好像没有提到:displayInterstitial(),onCreate()方法的任何地方,你确定代码执行到了displayInterstitial()方法?
It seems that you have not mentioned: displayInterstitial(), anywhere in onCreate() Method, You sure the code execution reaches the displayInterstitial() method?
此外,在广告完全加载并准备好展示后,代码会返回某个时间点.如:
Also, you will have some point where the code returns after the ad has been fully loaded and ready to display. Such as:
@Override
public void onReceiveAd(Ad ad) {
Log.d("OK", "Received ad");
if (ad == interstitial) {
interstitial.show();
}
}
这篇关于如何展示插页式广告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何展示插页式广告?


基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01