eclipse无法识别adMob新的AdRequest() [英] adMob new AdRequest() unrecognized by eclipse

查看:120
本文介绍了eclipse无法识别adMob新的AdRequest()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将广告添加到我的简单游戏中.我已经按照这里的指示进行操作:[url] https://github.com/libgdx/libgdx/wiki/Admob-in-libgdx[/url] . 我的AndroidLauncher看起来像这样:

I am trying to add ad to my simply game. I' ve followed instructions from here: [url]https://github.com/libgdx/libgdx/wiki/Admob-in-libgdx[/url] . My AndroidLauncher looks like this :

包com.redHoodie.android;

package com.redHoodie.android;

import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.google.ads.AdSize;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.redHoodie.MainHoodie;


public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Create the layout
        RelativeLayout layout = new RelativeLayout(this);

        // Do the stuff that initialize() would do for you
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

        // Create the libgdx View
        View gameView = initializeForView(new MainHoodie());

        // Create and setup the AdMob view
        AdView adView = new AdView(this, AdSize.BANNER, "xxxxx"); // Put in your secret key here
        adView.loadAd(new AdRequest());

        // Add the libgdx view
        layout.addView(gameView);

        // Add the AdMob view
        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);

        // Hook it all up
        setContentView(layout);


    }
}

这三行代码用eclipse下划线:

and this three rows of code are underlined by eclipse :

  View gameView = initializeForView(new MainHoodie(),false);

        // Create and setup the AdMob view
        AdView adView = new AdView(this, AdSize.BANNER, "xxxxx"); // Put in your secret key here
        adView.loadAd(new AdRequest());

ecllipse通知我删除这些方法的所有参数,但是当我这样做时,我的游戏在发布后立即崩溃.我正在使用libgdx 1.2

ecllipse tels me to remove all arguments of these methods, but when i dothis my game crush just after launch. I am using libgdx 1.2

推荐答案

您正在将旧的/过时的admob api与新的admob api(通过Google Play服务)混合在一起.你有:

You are mixing up the old/deprecated admob api with the new admob api(via google play services). You have:

import com.google.ads.AdSize;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

您必须坚持使用一种API.

You have to stick to one api.

如果是旧版本(例如libs/GoogleAdMobAdsSdk-6.4.1.jar),则必须从软件包中导入类:

If it's the old, thus libs/GoogleAdMobAdsSdk-6.4.1.jar, you'd have to import the classes from the packages:

    import com.google.ads.AdSize;
    import com.google.ads.AdRequest;
    import com.google.ads.AdView;

并设置广告视图:

//创建并设置AdMob视图

// Create and setup the AdMob view

    AdView adView = new AdView(this, AdSize.BANNER, "xxxxx"); // Put in your secret key here
    adView.loadAd(new AdRequest());

如果它是通过Google Play服务库提供的新admob,则您应该具有:

If it's the new admob via the google play services library, then you should have:

import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

       AdView adView = new AdView(this);
       adView.setAdSize(AdSize.BANNER);
       adView.setAdUnitId(AD_UNIT_ID);
       AdRequest adRequest = new AdRequest.Builder().build();
       adView.loadAd(adRequest);

这篇关于eclipse无法识别adMob新的AdRequest()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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