声明实例:
public static AdView adView;
初始化:
adView = new AdView(this);
adView.setAdUnitId(ADMOB_ID);
adView.setAdSize(AdSize.BANNER);
添加到Layout上
layout.addView(adView);
请求广告并显示:
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
AndroidManifest中添加:
Application标签下添加
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
声明Activity
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
整体逻辑没变,只是API名称和调用方式变了一下