adMob新的AdRequest()无法被eclipse识别

时间:2014-08-04 16:36:59

标签: java android libgdx admob

我正在尝试将广告添加到我简单的游戏中。我'我们遵循了这里的指示:[url] https://github.com/libgdx/libgdx/wiki/Admob-in-libgdx[/url]。 我的AndroidLauncher看起来像这样:

包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加下划线:

  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

1 个答案:

答案 0 :(得分:0)

您正在将旧的/已弃用的admob api与新的admob api混合(通过Google Play服务)。你有:

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

你必须坚持一个api。

如果它是旧的,即libs / GoogleAdMobAdsSdk-6.4.1.jar,则必须从包中导入类:

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

并设置广告视频:

//创建并设置AdMob视图

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

如果是通过Google Play服务库的新admob,那么您应该:

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);