以下代码是我为了检查 admob 广告检索而实施的,但我无法获得任何广告,尽管代码甚至没有崩溃。请告知此代码中有什么问题。
public class MainActivity extends Activity {
public AdView admobView;
public View mainView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
admobView = new AdView(this, AdSize.BANNER, "Top secret");
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
admobView.setLayoutParams(lp);
//mainView.setLayoutParams(lp);
RelativeLayout layout = new RelativeLayout(this);
AdRequest adRequest = new AdRequest();
//tested this
adRequest.addTestDevice(AdRequest.TEST_EMULATOR); // Emulator
//tested this
//adRequest.addTestDevice("20cb18e8ffc74ad2");
//tested this
//adRequest.addMediationExtra("3d879f364d5747c5", null);
admobView.loadAd(adRequest);
layout.addView(admobView);
//layout.addView(mainView);
setContentView(layout);
}