<bdo id='1A5aX'></bdo><ul id='1A5aX'></ul>
  • <i id='1A5aX'><tr id='1A5aX'><dt id='1A5aX'><q id='1A5aX'><span id='1A5aX'><b id='1A5aX'><form id='1A5aX'><ins id='1A5aX'></ins><ul id='1A5aX'></ul><sub id='1A5aX'></sub></form><legend id='1A5aX'></legend><bdo id='1A5aX'><pre id='1A5aX'><center id='1A5aX'></center></pre></bdo></b><th id='1A5aX'></th></span></q></dt></tr></i><div id='1A5aX'><tfoot id='1A5aX'></tfoot><dl id='1A5aX'><fieldset id='1A5aX'></fieldset></dl></div>
  • <tfoot id='1A5aX'></tfoot>
    <legend id='1A5aX'><style id='1A5aX'><dir id='1A5aX'><q id='1A5aX'></q></dir></style></legend>

    1. <small id='1A5aX'></small><noframes id='1A5aX'>

      1. 如何在 LibGDX And​​roid 项目中实施 AdMob 广告?

        时间:2023-05-19

        <i id='YdSpw'><tr id='YdSpw'><dt id='YdSpw'><q id='YdSpw'><span id='YdSpw'><b id='YdSpw'><form id='YdSpw'><ins id='YdSpw'></ins><ul id='YdSpw'></ul><sub id='YdSpw'></sub></form><legend id='YdSpw'></legend><bdo id='YdSpw'><pre id='YdSpw'><center id='YdSpw'></center></pre></bdo></b><th id='YdSpw'></th></span></q></dt></tr></i><div id='YdSpw'><tfoot id='YdSpw'></tfoot><dl id='YdSpw'><fieldset id='YdSpw'></fieldset></dl></div>
            <bdo id='YdSpw'></bdo><ul id='YdSpw'></ul>

            <small id='YdSpw'></small><noframes id='YdSpw'>

            <legend id='YdSpw'><style id='YdSpw'><dir id='YdSpw'><q id='YdSpw'></q></dir></style></legend>
                <tbody id='YdSpw'></tbody>

                  <tfoot id='YdSpw'></tfoot>
                • 本文介绍了如何在 LibGDX And​​roid 项目中实施 AdMob 广告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我发现了这个 Flappy Bird GIT 项目:https://github.com/barodapride/flappy-教程-巴罗达必利如何在此实施 BannerAd?没有布局文件.以及如何实施 InterstitialAd?如果我尝试写

                  I found this Flappy Bird GIT project: https://github.com/barodapride/flappy-tutorial-barodapride How can I implement the BannerAd in this? There is no layout file. And how can I implement the InterstitialAd? If I try to write

                  public InterstitialAd mInterstitialAd;
                  

                  然后它说无法解析符号 InterstitialAd"

                  Then it says "cannot resolve symbol InterstitialAd"

                  我知道如何在普通的 Android Studio 项目中执行此操作,但这是我第一次使用 libGDX,这太复杂了...

                  I know how to do this in a normal Android Studio project, but this is the first time I'm working with libGDX and this is so complicated...

                  推荐答案

                  我在这里回答了 这里,如何将 AdMob 横幅广告集成到 LibGDX 项目中.

                  I answered here, how you integrate AdMob banner Ad inside your LibGDX project.

                  现在我在集成横幅广告后回答InterstitialAd集成.

                  Now I answer InterstitialAd integration after Integration of banner Ad.

                  private static final String AD_UNIT_ID_INTERSTITIAL = "ca-app-pub-XXXXX/XXXXX";
                  
                  private InterstitialAd interstitialAd;
                  
                  @Override
                  protected void onCreate (Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                  
                      ...
                      ...
                  
                      interstitialAd = new InterstitialAd(this);
                      interstitialAd.setAdUnitId(AD_UNIT_ID_INTERSTITIAL);
                      interstitialAd.setAdListener(new AdListener() {
                            @Override
                            public void onAdLoaded() {}
                  
                            @Override
                            public void onAdClosed() {
                               loadIntersitialAd();
                            }
                      });
                  
                      loadIntersitialAd();
                  }
                  
                  
                  private void loadIntersitialAd(){
                  
                      AdRequest interstitialRequest = new AdRequest.Builder().build();
                      interstitialAd.loadAd(interstitialRequest);
                  }
                  
                  @Override 
                  public void showOrLoadInterstitial() {
                  
                       runOnUiThread(new Runnable() {
                              public void run() {
                                  if (interstitialAd.isLoaded()) 
                                       interstitialAd.show();                         
                                  else 
                                       loadIntersitialAd();           
                              }
                        });
                  }
                  

                  需要一个接口来从核心模块调用showOrLoadInterstitial,所以我在核心模块内部创建了IActivityRequestHandler,并将这个接口实现到android模块的AndroidLauncher.

                  Need an interface to call showOrLoadInterstitial from core module so I created IActivityRequestHandler inside core module and implement this interface to AndroidLauncher of android module.

                  public interface IActivityRequestHandler {
                  
                       void showOrLoadInterstitial();
                  }
                  

                  编辑

                  你不能用类/接口名称调用非静态方法,showOrLoadInterstitial(),需要一个IActivityRequestHandler实现类的对象,所以创建一个参数化构造函数MyGdxGame 并从 android 模块传递引用.

                  You can't call non-static method, showOrLoadInterstitial() with class/interface name, need an object of IActivityRequestHandler implemented class so create a parameterized constructor of MyGdxGame and pass reference from android module.

                   public class AndroidLauncher extends AndroidApplication implements IActivityRequestHandler  {
                  
                     @Override
                     protected void onCreate (Bundle savedInstanceState) {
                         super.onCreate(savedInstanceState);
                  
                         View gameView=initializeForView(new MyGdxGame(this));
                         ....
                         ....
                     }
                  

                  MyGdxGame游戏类中捕获IActivityRequestHandler的引用

                  public class MyGdxGame extends Game {
                  
                     Public IActivityRequestHandler requestHandler;
                  
                     public MyGdxGame(IActivityRequestHandler requestHandler){
                         this.requestHandler=requestHandler;
                     }
                  
                     ...
                  }
                  

                  现在你有了对象引用,可以调用 requestHandler.showOrLoadInterstitial()

                  Now you've object reference, can called requestHandler.showOrLoadInterstitial()

                  这篇关于如何在 LibGDX And​​roid 项目中实施 AdMob 广告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:导入 com.badlogic.gdx.graphics.gl10 无法解析 下一篇:LibGDX HelloWorld 项目在 Android 模拟器上运行时崩溃

                  相关文章

                  最新文章

                • <small id='iKb4j'></small><noframes id='iKb4j'>

                  <i id='iKb4j'><tr id='iKb4j'><dt id='iKb4j'><q id='iKb4j'><span id='iKb4j'><b id='iKb4j'><form id='iKb4j'><ins id='iKb4j'></ins><ul id='iKb4j'></ul><sub id='iKb4j'></sub></form><legend id='iKb4j'></legend><bdo id='iKb4j'><pre id='iKb4j'><center id='iKb4j'></center></pre></bdo></b><th id='iKb4j'></th></span></q></dt></tr></i><div id='iKb4j'><tfoot id='iKb4j'></tfoot><dl id='iKb4j'><fieldset id='iKb4j'></fieldset></dl></div>
                    <bdo id='iKb4j'></bdo><ul id='iKb4j'></ul>
                  <legend id='iKb4j'><style id='iKb4j'><dir id='iKb4j'><q id='iKb4j'></q></dir></style></legend>

                  <tfoot id='iKb4j'></tfoot>