0

i want to create an android app using phonegap , with a simple basic HTML page as showed in this tutorial.

http://pointdeveloper.com/how-to-add-banner-ads-to-phonegap...

https://phonegap.com/blog/2016/08/09/appfeel-guest-post/

After adding the following line to "config.xml"

<gap:plugin name="phonegap-admob" source="npm"/>

here is my "index.html" file

<!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/index.css">
 
</head>
        
<body onload="domLoaded()">
  <header>pointDeveloper.com</header>
        
  <div class="wrapper">Please Subscribe To My Channel and like the video
         
       
  </div>        
   
 <footer class="footer">This is spartaaaa</footer>
 
  <script src="cordova.js"></script>
  <script type="text/javascript" src="js/index.js" ></script>
  <script type="text/javascript" >
  function adSetter(){
alert(navigator.userAgent);
var admobid = {};
// select the right Ad Id according to platform
if( /(android)/i.test(navigator.userAgent) ) { 
    admobid = { // for Android
        banner: 'ca-app-pub-6136762217480399/8690615372',
        interstitial: 'ca-app-pub-6136762217480399/5002296586'
    };
} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
    admobid = { // for iOS
        banner: 'ca-app-pub-6869992474017983/4806197152',
        interstitial: 'ca-app-pub-6869992474017983/7563979554'
    };
} else {
    admobid = { // for Windows Phone
        banner: 'ca-app-pub-6869992474017983/8878394753',
        interstitial: 'ca-app-pub-6869992474017983/1355127956'
    };
}

if(AdMob) AdMob.createBanner( {
    isTesting:true,  //Remove this Before publishing your app
    adId:admobid.banner, 
    position:AdMob.AD_POSITION.BOTTOM_CENTER, 
    autoShow:true} );

}
  function onDeviceReady(){
  alert("device ready");
      adSetter();
   
  }


function domLoaded(){
 document.addEventListener("deviceready", onDeviceReady, false);
}
  </script>
</body>
 
</html>

After lot of testing on my android phone, even exporting the apk in the phonegap build, the apps is displpayed , but the bottom banner is nowhere

did i miss something ? thanks in advance

edit: Here are the errors shown in Chrome JavaScript Debugger Tools

Uncaught ReferenceError: domLoaded is not defined
    at onload ((index):10)
:3000/cordova_plugins.js Failed to load resource: the server responded with a status of 500 (Internal Server Error)
(index):27 Uncaught ReferenceError: admob is not defined
    at initAds ((index):27)
    at Channel.onDeviceReady ((index):97)
    at Channel.fire (cordova.js:777)
    at cordova.js:231
:3000/favicon.ico Failed to load resource: the server responded with a status of 404 (Not Found)
vipghost
  • 1
  • 2

1 Answers1

0

Its likely that you need to configure the cordova-plugin-whitelist to allow Admob to access the network.

edit: Add the plugin to your config.xml:

<plugin name="cordova-plugin-whitelist" />

Start with fully open access (in your config.xml) and see if your request is successful:

<access origin="*" />

If that works then you should determine which exact domains you need access to and restrict to that. If your requests still don't work then the problem may be somewhere else. Connect a JavaScript debugger (safari or Chrome) and see what errors are being thrown.

wildabeast
  • 1,723
  • 3
  • 18
  • 31