[英]How to integrate admob in phonegap android app?
我正在使用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:
您可以直接将此admob.js复制到您的项目中,并在index.html中引用:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.