我在我的项目中添加了google play服务库,之后我在清单文件中添加了元数据和admob的活动。然后我在主要活动中添加了插页式广告代码并调用了displayinterstitial(),但仍然没有展示广告。这些步骤缺少什么?下面是我的代码。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("APPID");
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getSupportActionBar();
SpannableString s = new SpannableString("Car Shop");
actionBar.setTitle(s);
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
@Override
public void onBackPressed() {.................}
@Override
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction arg1) {
viewPager.setCurrentItem(tab.getPosition());
displayInterstitial();
}
@Override
public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
}
答案 0 :(得分:0)
首先从
除此之外,您显示的代码看起来很好。看一下日志,它可能会在那里留言说没有可用的广告。