[英]Admob Adview Banner Ad show in Android apps
在我的活动中,我使用了这个
public class MainActivity extends Activity {
AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(
"BD9386F17F7DE795B86B5BBBEDDF1095").build();
adView.loadAd(adRequest);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
adView.pause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
adView.resume();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
adView.destroy();
}
}
在我的xml中,我使用了这个
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-5000769796423780/7961881354" />
在我的清单中
我已经使用了此权限
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
而且这个元数据
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
我一直在使用此代码,但这次却无法正常工作。 即使Logcat中没有错误。 最近,我使用了api-21。
您是否已将AdActivity添加到清单中 ?
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.