简体   繁体   English

使用Android Java代码进行Admob

[英]Admob With Android Java Code

I want to use AdMob but I want to write it in purely Java using no XML. 我想使用AdMob,但是我想用纯Java而不用XML编写它。 How can I display ads with the view class? 如何通过视图类展示广告?

Here is where I want to present it. 这是我要介绍的地方。 Because I am using framework code, here is where I draw my pixmaps. 因为我使用的是框架代码,所以这里是绘制像素图的地方。 And this is where the AdMob will be presented: 这是AdMob的展示位置:

   public void present(float deltaTime) {
        Graphics g = game.getGraphics();
        g.drawPixmap(Assets.background, 0, 0);
        g.drawPixmap(Assets.logo, 35, 30);
        g.drawPixmap(Assets.play, 74, 220);
        // Create the adView
 AdView adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());

Taken from: http://code.google.com/mobile/ads/docs/android/fundamentals.html 摘自: http : //code.google.com/mobile/ads/docs/android/fundamentals.html

You'll have to work with xml to add it to the Manifest and permissions though. 您将不得不使用xml将其添加到清单和权限中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM