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

喜你入骨 提交于 2019-11-28 02:16:21

问题


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 .


回答1:


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.




回答2:


of course we can add admob and or any other lib in your cocos2d games activity class.

You need to implement adlistener to your activity and add the adview in the OnStart() method of your game .



来源:https://stackoverflow.com/questions/17971120/can-we-use-googleads-admob-adwhirl-in-cocos2d-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!