Search code examples
androidcocos2d-android

Can we use GoogleAds/AdMob/AdWhirl in cocos2d-android?


I want to add the Admob / AdWhirl into the GameLayer Scene.

I search over everywhere but couldn't find the way to do this work. I don't want to switch the Library. So , what should i do?

If someone have worked on it , give some way to do this .


Solution

  • as there is not layout xml file for cocos2d android you can add it progammatically. crate linear layout in onstart method itself.

    like this

    LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(
                    getWindowManager().getDefaultDisplay().getWidth(),                        
                    getWindowManager().getDefaultDisplay().getHeight()+getWindowManager().getDefaultDisplay().getHeight()-50);
    
            adView = new AdView(SimpleGame.this, AdSize.BANNER, "your Ad ID");
    adView.setAdListener(SimpleGame.this);                            
            AdRequest request = new AdRequest();
            request.addTestDevice(AdRequest.TEST_EMULATOR);
            adView.loadAd(request);                
    
            CCDirector.sharedDirector().getActivity().addContentView(adView,adParams);
    

    this should be in try and catch.