3

我正在使用这个 AdMob 插件 ( https://github.com/rajpara11/phonegap-plugins/tree/master/Android/AdMobPlugin ) 在 Android 中投放 AdMob 广告。我没有收到任何广告,屏幕底部有一大块 (25%) 区域是白色的。我确实收到此错误“CordovaLog(275): TypeError: 表达式 'window.plugins' [undefined] 的结果不是对象。” 在模拟器中运行时在我的 Aptana/Eclipse 日志中。

文档设置说将“AdMob Cordova 插件 jar 放入 libs/”。只有一个 .Java 文件。我是否应该将其编译成 JAR 文件并将其放在该文件夹中?是否有任何教程显示此插件有效?

提前致谢

4

3 回答 3

0

通过在代码中注释掉这一行来修复它:

是测试:真

于 2015-02-13T19:03:04.110 回答
0

确保您在引用 AdMob 插件之前添加了对 Phonegap/Cordova 的引用,因为它取决于它。

你可以看看这个如何使用PhoneGap插件的视频教程:http ://www.youtube.com/watch?v=84jmuXS8GJI

祝你好运!

于 2013-05-28T13:54:05.773 回答
0

尝试一个不同的插件,因为听起来这个插件坏了。我知道这个有效

https://github.com/sunnycupertino/cordova-plugin-admob-simple

cordova plugin add cordova-plugin-admob-simple

整合如下:

-添加以下 javascript 函数,放入您自己的广告代码,如果您愿意,可以使用变量。

- 从 onDeviceReady() 调用 initAd(),并调用 showBannerFunc() 和 showInterstitialFunc() 来展示广告。

//initialize the goodies
function initAd(){
        if ( window.plugins && window.plugins.AdMob ) {
            var ad_units = {
                ios : {
                    banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx',       //PUT ADMOB ADCODE HERE
                    interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx'  //PUT ADMOB ADCODE HERE
                },
                android : {
                    banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx',       //PUT ADMOB ADCODE HERE
                    interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx'  //PUT ADMOB ADCODE HERE
                }
            };
            var admobid = ( /(android)/i.test(navigator.userAgent) ) ? ad_units.android : ad_units.ios;

            window.plugins.AdMob.setOptions( {
                publisherId: admobid.banner,
                interstitialAdId: admobid.interstitial,
                adSize: window.plugins.AdMob.AD_SIZE.SMART_BANNER,  //use SMART_BANNER, BANNER, IAB_MRECT, IAB_BANNER, IAB_LEADERBOARD
                bannerAtTop: false, // set to true, to put banner at top
                overlap: true, // banner will overlap webview 
                offsetTopBar: false, // set to true to avoid ios7 status bar overlap
                isTesting: false, // receiving test ad
                autoShow: false // auto show interstitial ad when loaded
            });

            registerAdEvents();
            window.plugins.AdMob.createInterstitialView();  //get the interstitials ready to be shown
            window.plugins.AdMob.requestInterstitialAd();

        } else {
            //alert( 'admob plugin not ready' );
        }
}
//functions to allow you to know when ads are shown, etc.
function registerAdEvents() {
        document.addEventListener('onReceiveAd', function(){});
        document.addEventListener('onFailedToReceiveAd', function(data){});
        document.addEventListener('onPresentAd', function(){});
        document.addEventListener('onDismissAd', function(){ });
        document.addEventListener('onLeaveToAd', function(){ });
        document.addEventListener('onReceiveInterstitialAd', function(){ });
        document.addEventListener('onPresentInterstitialAd', function(){ });
        document.addEventListener('onDismissInterstitialAd', function(){
            window.plugins.AdMob.createInterstitialView();          //REMOVE THESE 2 LINES IF USING AUTOSHOW
            window.plugins.AdMob.requestInterstitialAd();           //get the next one ready only after the current one is closed
        });
    }

//display the banner
function showBannerFunc(){
    window.plugins.AdMob.createBannerView();
}
//display the interstitial
function showInterstitialFunc(){
    window.plugins.AdMob.showInterstitialAd();
}
于 2016-03-26T17:44:18.860 回答