如何在app中的admob中放置广告

时间:2015-02-13 19:01:36

标签: android admob

如何在应用中使用广告 - 暴徒以及我在广告投放广告中发布广告的步骤如何在上传到Google Play商店之前在我的设备中进行测试。我是广告暴徒的新手。请逐步向我解释一下它的示例。

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        this.interstitialAds = new InterstitialAd(this, "ca-app-pub-****");
        this.interstitialAds.setAdListener(this);

        Button loadButton = (Button) this.findViewById(R.id.loadButton);
        loadButton.setOnClickListener(loadButtonOnClick);

        this.textView = (TextView) this.findViewById(R.id.stateTextView);
    }

    private OnClickListener loadButtonOnClick = new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            textView.setText("Loading Intertitial Ads");

            AdRequest adr = new AdRequest();
            // add your test device here
            adr.addTestDevice(AdRequest.TEST_EMULATOR);

            interstitialAds.loadAd(adr);
        }
    };

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

    }

    @Override
    public void onFailedToReceiveAd(Ad ad, ErrorCode error) {
        String message = "Load Ads Failed: (" + error + ")";
        textView.setText(message);
    }

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

    /**
     * Called when an Activity is created in front of the app (e.g. an
     * interstitial is shown, or an ad is clicked and launches a new Activity).
     */
    @Override
    public void onPresentScreen(Ad arg0) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onReceiveAd(Ad arg0) {
        if (interstitialAds.isReady()) {
            interstitialAds.show();
        } else {
            textView.setText("Interstitial ad was not ready to be shown.");
        }
    }
}

1 个答案:

答案 0 :(得分:1)

  1. 摆脱您的AdListener。
  2. 在构造函数中调用intersitial.loadAd
  3. 在应用中的自然断点处调用interstitial.show
  4. 致电interstitial.loadAd
  5. 转到3。
  6. 请参阅https://developers.google.com/mobile-ads-sdk/docs/admob/android/interstitial