如何以编程方式设置adUnitId?

时间:2012-11-02 10:25:51

标签: java android eclipse admob

如何以编程方式将adUnitId(Admob)添加到我的Android应用(eclipse)? 我将通过网络收到此ID!

AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest request = new AdRequest();
  

虚构: request.SETadUnitId(“ADUNITID”);

adView.loadAd(request);

2 个答案:

答案 0 :(得分:2)

好的,我删除了XML样式并以编程方式定义了AdView

`AdView adView = new AdView(activity, adSize, "MY_AD_UNIT_ID")`;

答案 1 :(得分:1)

之前的答案已过时。这个承包商已不复存在。你应该使用:

AdView mAdViewTemp = new AdView(this);
mAdViewTemp.setAdUnitId(bannerUnit);
mAdViewTemp.setAdSize(AdSize.BANNER);