您好,我的应用未在Android回收商视图中展示广告我想在我的应用底部展示广告,但不显示广告我不想展示原生广告我只想展示广告底部的单个横幅。它是一个字典应用程序,使用Sqlite数据库加载数据原生广告将不适合它。请你帮忙,这是我的代码。 主要活动.java
mAdView = (AdView) findViewById(R.id.adView);
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Toast.makeText(getApplicationContext(), "onAdFailedToLoad", Toast.LENGTH_LONG).show();
if (mAdView.getVisibility() == View.GONE) {
mAdView.setVisibility(View.VISIBLE);
}
}
@Override
public void onAdFailedToLoad(int errorCode) {
Toast.makeText(getApplicationContext(), "onAdFailedToLoad", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdOpened() {
Toast.makeText(getApplicationContext(), "onAdOpened", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdLeftApplication() {
Toast.makeText(getApplicationContext(), "onAdLeftApplication", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdClosed() {
Toast.makeText(getApplicationContext(), "onAdClosed", Toast.LENGTH_SHORT).show();
}
});
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
这是我的内容main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e2e2e2"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/adView"
android:descendantFocusability="blocksDescendants"
android:scrollbars="vertical"/>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"/>
</RelativeLayout>
答案 0 :(得分:0)
添加OnCreate
MobileAds.initialize(this,"Your ad unit id from admob");
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice("Add Your Device id").build();
mAdView.loadAd(adRequest);
覆盖方法
@Override
public void onPause() {
if (mAdView != null) {
mAdView.pause();
}
super.onPause();
}
@Override
public void onResume() {
super.onResume();
if (mAdView != null) {
mAdView.resume();
}
}
@Override
public void onDestroy() {
if (mAdView != null) {
mAdView.destroy();
}
super.onDestroy();
}
您的XML文件
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_home_footer" />