如何在Android中使用AdMob和phonegap

安裝AdMob PhoneGap插件
使用https://github.com/admob-google/admob-cordova下載插件,而後本地安裝
添加cordova plugin c:\phonegap-admob-plugin,或者在線安裝cordova 插件。
cordova plugin add com.admob.plugin

使用PhoneGap命令下載插件,而後本地安裝
添加 phonegap plugin c:\phonegap-admob-plugin。

使用PhoneGap的生成,增長配置
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

2.init AdMob PhoneGap插件
初始化插件後deviceready事件
admob.initAdmob("admob banner ID","admob interstitial ID");

3.展現橫幅的位置關係
AdMob裏有一些橫幅大小,BannerSize,你能夠建立本身的橫幅大小在AdMob廣告平臺可用,位置容納全部的相對位置常量。
<uses-feature android:name="android.hardware.microphone" android:required="false" />

能夠設置爲AdMob的更多的參數,如測試模式,適用於應用程序。
var admobParam=new  admob.Params();
//admobParam.extra={'keyword':"admob phonegame"};
//admobParam.isForChild=true;
admobParam.isTesting=true; admob.showBanner(admob.BannerSize.BANNER,admob.Position.TOP_CENTER,admobParam);

4.在絕對位置顯示橫幅
你能夠放置AdMob橫幅在絕對位置比關係位置容易。
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"

5.顯示AdMob的插播
顯示AdMob插播中的PhoneGap,cordova或 xdk應用是相同的步驟。緩存插播,而後它顯示在onInterstitialReceive功能或顯示它時,你的遊戲結束了。
document.addEventListener(admob.Event.onInterstitialReceive, onInterstitialReceive, false);//show in ad receive event fun need add receive listener
       admob.cacheInterstitial();                            // load admob Interstitial
       function onInterstitialReceive(message) {   //show in ad receive event fun
       admob.showInterstitial();
                            }

 function onGameOver(){    //call this fun to show when game over
        admob.isInterstitialReady(function(isReady){
            if(isReady){
            admob.showInterstitial();
            }
        });
  }

6.處理AdMob的廣告活動
你能夠處理AdMob的全部本地事件,做爲onInterstitialReceive,在admob.Event全部事件類型
function onAdmobEvent (message) {
    //do some on admob event
                        }
document.addEventListener(admob.Event.onBannerDismiss, onAdmobEvent, false);
document.addEventListener(admob.Event.onBannerFailedReceive, onAdmobEvent, false);
document.addEventListener(admob.Event.onBannerLeaveApplication, onAdmobEvent, false);
document.addEventListener(admob.Event.onBannerPresent, onAdmobEvent, false);
document.addEventListener(admob.Event.onBannerReceive, onAdmobEvent, false);
document.addEventListener(admob.Event.onInterstitialDismiss, onAdmobEvent, false);
document.addEventListener(admob.Event.onInterstitialFailedReceive, onAdmobEvent, false);
document.addEventListener(admob.Event.onInterstitialLeaveApplication, onAdmobEvent, false);
document.addEventListener(admob.Event.onInterstitialPresent, onAdmobEvent, false);
document.addEventListener(admob.Event.onInterstitialReceive, onAdmobEvent, false);

7.更多功能
• 隱藏AdMob的橫幅
admob.hideBanner()

• 若是插播加載成功進行測試
admob.isInterstitialReady(function(isReady){
         if(isReady){
        alert("admob Interstitial loaded");
    }
});android

相關文章
相關標籤/搜索