adMob new AdRequest() unrecognized by eclipse

不问归期 提交于 2019-12-12 05:04:42

问题


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 :

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


    }
}

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


回答1:


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;

You have to stick to one api.

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;

and set up the adview:

// Create and setup the AdMob view

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

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


来源:https://stackoverflow.com/questions/25123447/admob-new-adrequest-unrecognized-by-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!