前端之家收集整理的这篇文章主要介绍了
cocos2d-x在android下添加插屏广告,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
http://blog.csdn.net/wiyun_beijing/article/details/17912471
好吧,经过仔细研究,我发现其实在cocos2d-x的应用下添加的插屏广告,当用Jin调用代码时是在子线程中对UI进行操作,所以显然是不可能控制得了广告UI的,所以上一篇说的“无法添加”就当是屁话好了……反正我确实是只菜鸟……接下来把添加过程写出来,好让后继的菜鸟们能不费力的添加这类广告,甚至以自定义的方式来展示广告……
上面说过了用JIN调用插屏时是在子线程中操作UI,主线程UI不是安全线程,所以需要使用Handle来与主线程进行通信,让其在适时的时候按我们设定的方式去调用广告UI,下面是代码:
- public class GameActivity extends Cocos2dxActivity {
- private static InterstitialAd interstitialAd;
- public static final StringPUBLISHER_ID="56OJzCCIuNT9GZxMAZ";
- public static final StringInlinePPID="16TLmbLoAp3B1NUGss77M4ai";
- public static final StringInterstitialPPID="16TLmbLoAp3B1NUGs4bP4d9i";
- static DomobInterstitialAd mInterstitialAd;
- private static Handler mHandler;
- protected void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- mHandler=newHandler();
- mInterstitialAd=newDomobInterstitialAd(this,PUBLISHER_ID,
- InterstitialPPID,DomobInterstitialAd.INTERSITIAL_SIZE_300X250);
- mInterstitialAd.setInterstitialAdListener(new DomobInterstitialAdListener() {
- @Override
- public void onInterstitialAdReady() {
- Log.i("DomobSDKDemo","onAdReady");
- }
- @Override
- public void onLandingPageOpen() {
- }
- public void onLandingPageClose() {
- public void onInterstitialAdPresent() {
- public void onInterstitialAdDismiss() {
- // Request new ad when the prevIoUs interstitial ad was closed.
- mInterstitialAd.loadInterstitialAd();
- public void onInterstitialAdLeaveApplication() {
- public void onInterstitialAdClicked(DomobInterstitialAd arg0) {
- public void onInterstitialAdFailed(
- cn.domob.android.ads.DomobAdManager.ErrorCode arg0) {
- // TODO Auto-generated method stub
- Failed");
- });
- mInterstitialAd.loadInterstitialAd();
- }