Search code examples
cordovaandroid-emulatorcordova-pluginsmime-types

Cordova Admob free plugin in javascript - Plugin not working


I have a problem with Cordova project. I want to use plugin admob cordova free (https://github.com/ratson/cordova-plugin-admob-free) for show admob advertising in my app, but i can not show the banners and interstitial ad. I tried everything without success, that is the reason I ask to the stack overflow community.

My code is here:

<!DOCTYPE html>

<html>
    <head>
        <meta charset="utf-8">
    
        <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
        <meta name="color-scheme" content="light dark">
        <link rel="stylesheet" href="css/index.css">
        <title>Cordova Admob Free</title>
    </head>
    <body>
        <div>
         <button id="interstitialad" >insterstitial ad<button>
         
        </div>
        <script src="js/cordova.js"></script>
        <script src="text/javascript">
        document.addEventListener('deviceready', function() {
          admob.banner.prepare();
          admob.banner.show({ 
            id : 'ca-app-pub-3940256099942544/6300978111',
             autoShow:true
          
          })
        
        }, false);
        
        
        document.getElementById('interstitialad').addEventListerner('click', interstitialad);
        
        function interstitialad() {
        
           admob.insterstitial.config({
              id: 'ca-app-pub-3940256099942544/1033173712'
           
           });
            admob.insterstitial.prepare();
        
        }
        </script> -->
    </body>
</html>

I follow the tutorial in this youtube video: https://www.youtube.com/watch?v=10Yww_fq3bw but I dont have any success. I run the code in the Android Emulator, without no success. Do you know how to see logs in the android emulator?

I try to see the console.logs from browser platform in cordova, running "cordova run browser". And I get the following errors:

The resource from “http://localhost:8000/text/javascript” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff). index.html Loading failed for the with source “http://localhost:8000/text/javascript”.

Thank you and Best Regards,

Paul


Solution

  • Your ad preparation is in the wrong order!

    You need to make the config first and then prepare it. At the end you show it!

    Here is an example:

    admob.banner.config({
     id: 'ca-app-pub-xxx/xxx',
    })
    
    // Create banner
    admob.banner.prepare()
    
    // Show the banner
    admob.banner.show()