将admob添加到mainactivity.java

时间:2014-11-25 08:50:42

标签: java eclipse

我需要帮助,我想按照以下步骤https://github.com/libgdx/libgdx/wiki/Admob-in-libgdx使用Eclipse i向我的应用添加admob,我从这段代码中得到了很多错误

任何想法?

包com.kilobolt.ZombieBird;

导入android.os.Bundle;

import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;

公共类MainActivity扩展AndroidApplication实现IActivityRequestHandler {     受保护的AdView adView;

private final int SHOW_ADS = 1;
private final int HIDE_ADS = 0;

protected Handler handler = new Handler()
{
    @Override
    public void handleMessage(Message msg) {
        switch(msg.what) {
            case SHOW_ADS:
            {
                adView.setVisibility(View.VISIBLE);
                break;
            }
            case HIDE_ADS:
            {
                adView.setVisibility(View.GONE);
                break;
            }
        }
    }
};

@Override
public 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 HelloWorld(this), false);

    // Create and setup the AdMob view
    adView = new AdView(this, AdSize.BANNER, "xxxxxxxx"); // 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);
}

// This is the callback that posts a message for the handler
@Override
public void showAds(boolean show) {
   handler.sendEmptyMessage(show ? SHOW_ADS : HIDE_ADS);

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

    initialize(new ZBGame(), cfg);

}

}

0 个答案:

没有答案