错误是什么?因为不会显示admob插页式广告?
public class MainActivity extends Activity implements AdListener {
private InterstitialAd interstitial;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the interstitial
interstitial = new InterstitialAd(this, "ca-app-pub-6xxxxxxxx/xxxxxx");
// Create ad request
AdRequest adRequest = new AdRequest();
// Begin loading your interstitial
interstitial.loadAd(adRequest);
// Set Ad Listener to use the callbacks below
interstitial.setAdListener(this);
}
public void onReceiveAd(Ad ad) {
// TODO Auto-generated method stub
Log.d("ads", "onReceiveAd");
if (ad == interstitial)
interstitial.show();
}
谢谢我不知道因为不会显示
答案 0 :(得分:0)
请按照以下示例
import com.google.android.gms.ads.*;
public class BannerExample extends Activity {
private InterstitialAd interstitial;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Create the interstitial.
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(MY_AD_UNIT_ID);
// Create ad request.
AdRequest adRequest = new AdRequest.Builder().build();
// Begin loading your interstitial.
interstitial.loadAd(adRequest);
}
//Invoke displayInterstitial() when you are ready to display an interstitial.
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
}
答案 1 :(得分:0)
您应该在.build()
创建结束时添加AdRequest
。
// Create ad request
AdRequest adRequest = new AdRequest().build();