Admob广告根本不显示

时间:2017-07-19 17:20:47

标签: android eclipse admob

我遇到Admob广告根本没有显示的问题,我认为我做的一切都正确,但他们仍然无法展示。 我在代码中搜索试图找出任何错误但似乎没有错 请任何解决方案?!!

这是MainActivity.java:

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.google.ads.Ad;
import com.google.ads.AdListener;
import com.google.ads.AdRequest;
import com.google.ads.AdRequest.ErrorCode;
import com.google.ads.InterstitialAd;

public class MainActivity extends AndroidApplication implements
AdListener {

    private ActionResolverAndroid actionResolverAndroid;
    private InterstitialAd interstitialAdMob;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        interstitialAdMob = new InterstitialAd(MainActivity.this,"ca-app-pub-3940256099942544/1033173712");
        interstitialAdMob.setAdListener(this);
        interstitialAdMob.loadAd(new AdRequest());
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(
                WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

        AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
        cfg.useWakelock = true;
        cfg.useGL20 = false;

        actionResolverAndroid = new ActionResolverAndroid(this,
                startAppInterHandler);
        View v = initializeForView(new JetPig(actionResolverAndroid), cfg);
        setContentView(v);
    }

    private boolean startAppExit;

    public Handler startAppInterHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            // if (startAppAd.isReady())
            //
            // {
            switch (msg.what) {
            case 1:
                if (interstitialAdMob.isReady())
                interstitialAdMob.show(); // show the ad
                else
                interstitialAdMob.loadAd(new AdRequest()); // load the next ad
                break;
            case 2:
                if (interstitialAdMob.isReady()) {
                    interstitialAdMob.show();
                    startAppExit = true;
                } else
                    finish();

            default:
                break;
            }
            Gdx.app.log("Add", "In ShowStartApp Hanlder");

            // }
        }
    };

    public boolean isNetworkAvailable() {
        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager
                .getActiveNetworkInfo();
        return activeNetworkInfo != null;
    }

    public void finishActivity() {
        finish();
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onStop() {
        super.onStop();
    }


    @Override
    public void onDismissScreen(Ad arg0) {
        // TODO Auto-generated method stub
        if (startAppExit) {
            Gdx.app.log("Add", "Finsh");
            finish();
        }
        else
        {
            interstitialAdMob.loadAd(new AdRequest());
        }
    }

    @Override
    public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onLeaveApplication(Ad arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onPresentScreen(Ad arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onReceiveAd(Ad arg0) {
        // TODO Auto-generated method stub

    }
}

1 个答案:

答案 0 :(得分:0)

如果您的应用处于测试模式,则应在请求生成器上调用addTestDevice(AdRequest.DEVICE_ID_EMULATOR)

AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);  //  <- For testing
adView.loadAd(adRequestBuilder.build());

在LibGDX项目中集成AdMob

我建议您使用Android Studio或IntellijIDEA而不是Eclipse !!! --- why