广告不可见.不刷新广告 [英] Ad is not visible. Not refreshing ad

查看:86
本文介绍了广告不可见.不刷新广告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个免费的Android游戏,我想在上面添加横幅.我遵循了本教程,但我没有知道为什么它行不通.

I have made a free android game and I wanted to add a banner to it. I followed this tutorial and I don't know why it won't work.

当我在LogCat中的模拟器上运行游戏时,看到一条消息广告不可见.不刷新广告."而且当我在手机上安装游戏时,我也看不到任何广告.

When I run my game on the emulator in LogCat I see a message "Ad is not visible. Not refreshing ad." and when I install the game on my phone I also don't see any ads.

这是我的main.xml

Here is my main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/res-auto"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
  <com.google.android.gms.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="hidden"
                         ads:adSize="BANNER"/>
</LinearLayout>

这是MainActivity.java中的代码

and here is the code in MainActivity.java

public class MainActivity extends AndroidApplication {
    private AdView adView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
        cfg.useGL20 = true;
        cfg.useAccelerometer = true;
        cfg.useCompass = true;

        setContentView(R.layout.main);

        // Look up the AdView as a resource and load a request.
        adView = (AdView)this.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);

        initialize (new RedSquare(), cfg);
    }

    @Override
    public void onPause() {
      adView.pause();
      super.onPause();
    }

    @Override
    public void onResume() {
      super.onResume();
      adView.resume();
    }

    @Override
    public void onDestroy() {
      adView.destroy();
      super.onDestroy();
    }
}

推荐答案

要在libgdx中显示广告,您需要初始化您的应用以供查看.因此,请替换所有这些内容:

To show ads in libgdx you need to initialize your app for view. So, replace all this:

setContentView(R.layout.main);

// Look up the AdView as a resource and load a request.
adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);

initialize (new RedSquare(), cfg);

与此:

RelativeLayout layout = new RelativeLayout(this);

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
View gameView = initializeForView(new RedSquare(), cfg);

AdView AdView = new AdView(this);
AdView.setAdSize(AdSize.SMART_BANNER);
AdView.setAdUnitId("***"); //The AdUnitId
AdRequest.Builder adRequest = new AdRequest.Builder();
adRequest.addTestDevice("***"); //Your Test device if any
AdView.loadAd(adRequest.build());

layout.addView(gameView);

RelativeLayout.LayoutParams adParams = 
    new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

layout.addView(AdView, adParams);

setContentView(layout);

这篇关于广告不可见.不刷新广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆