【发布时间】:2015-04-26 19:53:53
【问题描述】:
编辑: ImageButton 播放用于启动新活动,我希望它在我点击它后加载插页式广告,它应该在活动之前显示广告。请帮我编辑此代码。我完全迷失了......
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.AdRequest;
private InterstitialAd interstitial;
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.loadingscreen);
interstitial = new InterstitialAd(Intro.this);
interstitial.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("F7D422E96C746A6BB1D1DB432FEA62C6")
.build();
interstitial.loadAd(adRequest);
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
displayInterstitial();
}
});
ImageButton play = (ImageButton) findViewById(R.id.play);
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent("com.mycompany.FattyPillow.MAINPAGE"));
}
});
}
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
【问题讨论】:
-
强烈建议您不要从
onAdLoaded()拨打interstitial.show(),除非您想要惹恼您的用户并获得Admob帐户禁止。 -
在我的广告正常工作后,我会立即考虑这些问题 :)
标签: android admob show interstitial