DEMO下载:http://download.csdn.net/detail/oyangyufu/7652803
1、声明Activity
<!-- 声明百度的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类中,初始广告对象
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、显示广告
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调用
public static void showInterstitialStatic() {
Message msg = handler.obtainMessage();
msg.what = 3;
handler.sendMessage(msg);
}
5、效果图,点show
版权声明:本文博客原创文章,博客,未经同意,不得转载。