我正在使用phonegap开发android应用程序,并尝试将admob集成到我的代码中。问题是"广告没有显示在索引页上。"我使用的是admobpro插件。请帮助我。这是index.html编码(admob脚本直接添加到索引页,而不是单独的js)
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css" />
<link rel="stylesheet" href="css/mycss.css" />
<script src="css/jquery-1.11.1.min.js"></script>
<script src="css/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<script>
var admobid = {};
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
banner: 'xxxxxxxxxxxxxxxxxxxx',
interstitial: 'xxxxxxxxxxxxxxxxxxxx'
};
} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
admobid = { // for iOS
banner: 'xxxxxxxxxxxxxxxxxxxx',
interstitial: 'xxxxxxxxxxxxxxxxxxxx'
};
} else {
admobid = { // for Windows Phone
banner: 'xxxxxxxxxxxxxxxxxxxx',
interstitial: 'xxxxxxxxxxxxxxxxxxxx'
};
}
if(( /(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent) )) {
document.addEventListener('deviceready', initApp, false);
window.alert("arun here")
} else {
initApp();
}
function initApp() {
if (! AdMob ) { alert( 'admob plugin not ready' ); return; }
AdMob.createBanner( {
adId: admobid.banner,
isTesting: true,
overlap: false,
offsetTopBar: false,
position: AdMob.AD_POSITION.BOTTOM_CENTER,
bgColor: 'black'
} );
AdMob.prepareInterstitial({
adId: admobid.interstitial,
autoShow: true
});
}
</script>
<div data-role="page" id="quest">
<div data-role="header" data-position="fixed">
<h1>Hello World</h1>
</div><!-- /header -->
<div data-role="content" class="links_home">
<!--<h1>links</h1> -->
<ul>
<li><a href="#Ans1">This Link 1</a></li>
<li><a href="#Ans2">This Link 2</a></li>
<li><a href="#Ans3">This Link 3</a></li>
<li><a href="#Ans4">This Link 4</a></li>
<li><a href="#Ans5">This Link 5</a></li>
</ul>
</div><!-- /content -->
<!--<div data-role="footer" data-position="fixed">
<h4>Page Footer</h4>
</div> /footer -->
</div><!-- /page -->
</body>
</html>
cordova.js是javascript和本机代码之间的cordova桥梁,如果缺少它,插件将不会被调用。
您忘记在index.html.中添加cordova.js
<script src="cordova.js"></script>
请参阅此处的示例index.html:
- https://github.com/floatinghotpot/admob-demo-game-phaser/blob/master/demo/index.html
您可以直接将此admob.js复制到您的项目中,并在index.html:中引用
- https://github.com/floatinghotpot/admob-demo-game-phaser/blob/master/demo/js/admob.js