2

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 .

Akarsh M
  • 1,629
  • 2
  • 24
  • 47

2 Answers2

3

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.

Sandeep R
  • 2,284
  • 3
  • 25
  • 51
  • This is add into the CCScene – Akarsh M Aug 01 '13 at 11:52
  • 1
    no not in CCscene, nothing to add in CCscene. add this in main activity in onstart() method. – Sandeep R Aug 01 '13 at 11:58
  • adView.setAdListener(SimpleGame.this); this line is not correct . It shows to add the Adlistener not Activity – Akarsh M Aug 01 '13 at 12:29
  • did you implement adlistener to the activity? like i said in the first comment? and replace " SimpleGame.this" with your activity name. I think you are a newB in android. no problem. there is something new to learn everyday. – Sandeep R Aug 01 '13 at 12:33
  • if you got what you need, please upvote my answer and accept it. – Sandeep R Aug 01 '13 at 12:41
  • what is the mean of (AdRequest.TEST_EMULATOR/Logcat/...); – Akarsh M Aug 01 '13 at 13:40
  • 1
    its used for testing the ads in emulator. but when you run it in device it will show live ads and you will start getting profits out of it. – Sandeep R Aug 01 '13 at 15:24
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/34671/discussion-between-sandeep-and-a-m) – Sandeep R Aug 02 '13 at 05:45
0

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 .

Sandeep R
  • 2,284
  • 3
  • 25
  • 51
  • Thanks for the rly but what about the manifest.xml things BECAUSE in the Cocos2d-android all working is run on CCScene which is not depenable on the xml Layout – Akarsh M Aug 01 '13 at 09:00
  • In android menifest add the adActivity same as in any other application. CCscene just has the scene of the game. – Sandeep R Aug 01 '13 at 10:28