I'm trying to integrate an admob banner into my Android game. I have a somewhat special case as my game screen is handled by a custom class that extends SurfaceView. I implemented the code from this page: http://rx-games.com/admob-adverts-on-surfaceview-no-xml-tutorial/ and it all compiles and runs w开发者_如何学运维ithout error.
Problem is, there are no ads and there is no banner when I run it on either my real device or my emulator. I feel like I somehow need to implement something like: "AdManager.setTestDevices( new String[] { AdManager.TEST_EMULATOR } );" like the page says, but the new google.ads package doesn't contatin an AdManager class.
Anyone have any experience with this? I need to know if the ad banner works or not before I send out this next game update. I can provide any code you'd like to see, but it is all exactly the same as in the above link. Let me know, thanks
I found that the problem was in the way the example called the ads. Instead of using their method showAd(), I needed to use this code right after my call to setContentView():
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
That gets it to work. Just remember to take out the testing line when publishing.
i had the same problem, my custom surface view means ads dont show.
in you main.xml it looks something like this:
LinearLayout (Fill, Parent, Fill Parent) - Customs Surface View (Fill Fill)
add a new layout to hold a top banner ad:
LinearLayout (Fill, Parent, Fill Parent) - LinearLayoutAd (Wrap Vertical, Fill Horizontal) - Customs Surface View (Fill Fill)
now put your ad in the linearlayoutad. This might affect any screen metrics you have as your custom surface is now smaller.
精彩评论