cocos2dx AdMob for Android

先根据开发者网站的文档配置好文件  


之后在Eclipse这边编辑.java文件

private static final String ADMOB_ID = "ca-app-pub-4585434383664955/2601194423";

static public AppActivity mAppActivity = null;

 

InterstitialAd mInterstitialAd;

private static AdRequest adRequest;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

mAppActivity = this;

mInterstitialAd = new InterstitialAd(this);

mInterstitialAd.setAdUnitId(ADMOB_ID);

        requestNewInterstitial();

        

        mInterstitialAd.setAdListener(new AdListener() {

            @Override

            public void onAdClosed() {

                requestNewInterstitial();

            }

        });

        

}


    private void requestNewInterstitial() {

     adRequest = new AdRequest.Builder().build();

      mInterstitialAd.loadAd(adRequest);

    }

    

    

  //egg carton

    public static Object getInstance(){

    return mAppActivity;

    }

  //egg carton

    public void  showAdInScreen(){

     runOnUiThread(new Runnable() {//此处是重点

            @Override public void run() {

                if (mInterstitialAd.isLoaded()) {

                mInterstitialAd.show();

             }

            }

        });

    }



c++那边使用JniHelper调用showAdInScreen()函数即可



你可能感兴趣的:(cocos2d-x,admob,android)