0

我不明白 InterstitialAd,我找不到任何示例。如果您有示例,您可以发布它。我尝试横幅是否有效。但是当我尝试 InterstitialAd 时出现错误。我想在打开应用程序时看到广告。

谢谢!!

package com.example.reklam3;

import android.app.Activity;

import com.google.ads.*;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

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 Activity implements AdListener{

  private InterstitialAd interstitial;

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

    // Create the interstitial
    interstitial = new InterstitialAd(this,"ca-app-pub-90707885707358xx");

    // Create ad request
    AdRequest adRequest = new AdRequest();

    // Begin loading your interstitial
    interstitial.loadAd(adRequest);

    // Set Ad Listener to use the callbacks below
    interstitial.show();
  }

  @Override
  public void onReceiveAd(Ad ad) {
    Log.d("OK", "Received ad");
    if (ad == interstitial) {
      interstitial.show();
    }
  }

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

}

@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

}
}

如果你有一个简单的例子,你能把它贴出来吗.ty

4

1 回答 1

0

我刚刚在这里发布了关于这个问题的答案:

https://stackoverflow.com/a/24150614/1287856

基本上,您需要:

  • 打电话adRequest.build()之前// Begin loading your interstitial
于 2014-06-10T21:02:14.360 回答