我有一個libgdx遊戲,我成功地添加了Admob廣告。當我使用Android Studio在我的物理設備上運行該應用時,它顯示了廣告,因爲我使用我的設備作爲測試設備,但是當我通過手機將其發送到其他設備時,它沒有顯示廣告。它只顯示一個沒有廣告的黑色矩形,因爲我將adView背景設置爲黑色。廣告不出現
我的問題是:是否應該將其上傳到Google Play商店來展示廣告或什麼?
這裏是我的代碼:
protected AdView adView;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout layout = new RelativeLayout(this);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
View gameView = initializeForView(new GameMain(), config);
layout.addView(gameView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setVisibility(View.VISIBLE);
AdRequest.Builder builder = new AdRequest.Builder();
adView.loadAd(builder.build());
adView.setBackgroundColor(0xff000000);
adView.setAdUnitId("xxxxxxxxxxxxxxxxxxx");
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT );
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layout.addView(adView, adParams);
setContentView(layout);
}
請檢查我的回答 – Shailesh