如何在phonegap安卓应用程序中集成admob
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:
- 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
相关文章:
- 在我的SPA应用程序中集成Facebook共享的问题
- 如何将tesseract OCR与Cordova/Phonegap应用程序集成
- 如何将现有的angular js应用程序集成到Laravel 5中
- 单页应用程序的javascript集成测试
- 如何将ember应用程序集成到json服务器中使用
- 如何将Google Analytics集成到GWT应用程序中
- IBM Filenet如何与Angular应用程序集成
- 将Google Places API与Rails应用程序集成
- 如何将Angular 2应用程序集成到Django应用程序中
- 将登录验证模块与现有的Angular JS应用程序集成
- 将大气层上的中等编辑器与望远镜应用程序集成
- 将 Outlook 与 JS Web 应用程序集成
- 将Javascript函数与Grails应用程序集成
- 如何将Crashlytics与React Native应用程序集成
- 是否有可能/可行将非microsoft REST客户端应用程序集成到Sharepoint 2013 OAuth中以获取R
- 将支付网关与angularjs应用程序集成到spring后端
- 我应该如何在我的应用程序集成谷歌地图
- 初学者问题:如何将processing.js与Rails 3.1应用程序集成
- Facebook, Twitter与Phonegap应用程序集成,无需使用插件
- 将R及其图形与现有的Javascript/HTML应用程序集成