您的位置:首页 > 其它

如何使用AdMob在PhoneGap应用程序导航库中添加插入式广告

2016-02-26 00:00 381 查看
首先我们准备好一个已经成功添加横幅广告的项目,然后进行如下步骤操作:
(步骤1)
我们将需要添加链接到index.html文件,如下所示: https://github.com/admob-google/admob-cordova
(步骤2)
创建两个新的文件连接到IE,contact.html和about.html、contact.htm
<!DOCTYPE html>
<html>
<head>
<title>Title Of The App</title>
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, min-height=device-height" />
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<header>Contact Page</header>
<a href="index.html">Index</a>
<div class="wrapper">Please Subscribe To My Channel and like the video</div>
<footer class="footer">This is page footer</footer>
<script src="cordova.js"></script>
<script type="text/javascript" src="js/contact.js" ></script>
</body>
</html>

about.html
<!DOCTYPE html>
<html>
<head>
<title>Title Of The App</title>
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, min-height=device-height" />
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<header>About Page</header>
<a href="index.html">Index</a>
<div class="wrapper">Please Subscribe To My Channel and like the video</div>
<footer class="footer">This is page footer</footer>
<script src="cordova.js"></script>
</body>
</html>
style.css文件将保持一样的如何添加横幅广告帖子。

(步骤3)
添加如下文件:
admob.initAdmob("admob banner ID","admob interstitial ID");

完成后应如下:
admob.showBanner(admob.BannerSize.BANNER,admob.Position.TOP_APP); //show banner at the top of app

document.addEventListener(admob.Event.onInterstitialReceive, onInterstitialReceive, false); //show in ad receive event fun need add receive listener

admob.cacheInterstitial();// load admob Interstitial

function onInterstitialReceive(message) { //show in ad receive event fun
admob.showInterstitial();
}

function onGameOver(){ //call this fun to show when game over
admob.isInterstitialReady(function(isReady){
if(isReady){
admob.showInterstitial();
}
});
}

(步骤4)
创建contact.js文件,检测页面,如果页面链接到.html则显示插入式广告,否则不显示广告。
function onAdmobEvent (message) {
//do some on admob event
}

document.addEventListener(admob.Event.onBannerDismiss, onAdmobEvent, false);
document.addEventListener(admob.Event.onBannerFailedReceive, onAdmobEvent, false);
document.addEventListener(admob.Event.onBannerLeaveApplication, onAdmobEvent, false);
document.addEventListener(admob.Event.onBannerPresent, onAdmobEvent, false);
document.addEventListener(admob.Event.onBannerReceive, onAdmobEvent, false);
document.addEventListener(admob.Event.onInterstitialDismiss, onAdmobEvent, false);
document.addEventListener(admob.Event.onInterstitialFailedReceive, onAdmobEvent, false);
document.addEventListener(admob.Event.onInterstitialLeaveApplication, onAdmobEvent, false);
document.addEventListener(admob.Event.onInterstitialPresent, onAdmobEvent, false);
document.addEventListener(admob.Event.onInterstitialReceive, onAdmobEvent, false);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: