在cocos2d-x中如何嵌入百度的插屏广告

在cocos2d-x中如何嵌入百度的插屏广告,第1张

概述DEMO下载:http://download.csdn.net/detail/oyangyufu/7652803  演示的效果请看这里:http://pan.baidu.com/s/1o6oit9w 1、声明Activity [cpp] view plain copy print ? <!-- 声明百度的Activity -->       <meta-data android:name="Bai

DEMO下载:http://download.csdn.net/detail/oyangyufu/7652803

演示的效果请看这里:http://pan.baidu.com/s/1o6oit9w

1、声明Activity

[cpp] view plain copy print ? <!--声明百度的Activity--> <Meta-dataandroID:name="BaIDuMobAd_APP_ID"androID:value="deBUG"/> <Meta-dataandroID:name="BaIDuMobAd_APP_SEC"androID:value="deBUG"/> <activityandroID:name="com.baIDu.mobads.AppActivity" androID:configChanges="keyboard|keyboardHIDden|orIEntation"/>
 <!-- 声明百度的Activity -->		<Meta-data androID:name="BaIDuMobAd_APP_ID" androID:value="deBUG" /> 		<Meta-data androID:name="BaIDuMobAd_APP_SEC" androID:value="deBUG" />		<activity androID:name="com.baIDu.mobads.AppActivity" 		    androID:configChanges="keyboard|keyboardHIDden|orIEntation" />


2、在主Activity类中,初始广告对象

[cpp] view plain copy print ? interad=newInterstitialAd(this); interad.setListener(newInterstitialAdListener(){ @OverrIDe publicvoIDonAdClick(InterstitialAdarg0){ Log.i("InterstitialAd","onAdClick"); } @OverrIDe publicvoIDonAddismissed(){ Log.i("InterstitialAd","onAddismissed"); interad.loadAd(); } @OverrIDe publicvoIDonAdFailed(Stringarg0){ Log.i("InterstitialAd","onAdFailed"); } @OverrIDe publicvoIDonAdPresent(){ Log.i("InterstitialAd","onAdPresent"); } @OverrIDe publicvoIDonAdReady(){ Log.i("InterstitialAd","onAdReady"); } }); //加载广告 interad.loadAd();
interad=new InterstitialAd(this);		interad.setListener(new InterstitialAdListener(){			@OverrIDe			public voID onAdClick(InterstitialAd arg0) {				Log.i("InterstitialAd","onAdClick");			}			@OverrIDe			public voID onAddismissed() {				Log.i("InterstitialAd","onAddismissed");				interad.loadAd();			}			@OverrIDe			public voID onAdFailed(String arg0) {				Log.i("InterstitialAd","onAdFailed");			}			@OverrIDe			public voID onAdPresent() {				Log.i("InterstitialAd","onAdPresent");			}			@OverrIDe			public voID onAdReady() {				Log.i("InterstitialAd","onAdReady");			}					});		//加载广告		interad.loadAd();

3、显示广告

[cpp] view plain copy print ? handler=newHandler(){ @OverrIDe publicvoIDhandleMessage(Messagemsg){ //Todoauto-generatedmethodstub switch(msg.what){ case3: //publicvoIDonClick(VIEwarg0){ if(interad.isAdReady()){//读取是否成功 Log.i("InterstitialAd","showAd"); interad.showAd(Test.this);//显示 }else{ interad.loadAd(); Log.i("InterstitialAd","loadAd..."); } break; } } };
handler = new Handler(){					@OverrIDe			public voID handleMessage(Message msg) {				// Todo auto-generated method stub				switch (msg.what) {				case 3:													//public voID onClick( VIEw arg0 ) {							if(interad.isAdReady()){//读取是否成功								Log.i("InterstitialAd","showAd");								interad.showAd(Test.this);//显示							}else{								interad.loadAd();								Log.i("InterstitialAd","loadAd...");							}					break;				}			}		};


4、定义静态函数,用于cpp调用

[cpp] view plain copy print ? publicstaticvoIDshowInterstitialStatic(){ Messagemsg=handler.obtainMessage(); msg.what=3; handler.sendMessage(msg); }
public static voID showInterstitialStatic() {		Message msg = handler.obtainMessage();		msg.what = 3;		handler.sendMessage(msg);	}

5、效果图,点show

总结

以上是内存溢出为你收集整理的在cocos2d-x中如何嵌入百度的插屏广告全部内容,希望文章能够帮你解决在cocos2d-x中如何嵌入百度的插屏广告所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1032481.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存