谷歌admob没有在我的Android应用程序上显示广告

时间:2018-04-23 02:03:24

标签: android firebase android-studio admob google-admob

我已经在我的Android应用中集成了firebase admob,并且已正确设置adview工作,但是logcat不断显示以下消息: logcat message

并且我已经尝试了在admob文档网站上提供的测试adunit id,它工作正常,但是当我切换到我自己的admob app id和广告单元广告时,它只是没有用,可以有人帮帮我吗?非常感激!

这是我的代码:

   @Override
  public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setHasOptionsMenu(true);

    MobileAds.initialize(getActivity(), "admob app id");
    fetchBooks();
  }


  @Override
  public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_book_gallery, container, false);

    //.........

    adView = v.findViewById(R.id.ad_view);
    AdRequest request = new AdRequest.Builder().addTestDevice("AE61276545183AF0466F05469FD032CC").build();
    adView.loadAd(request);

    //...........

    return v;
  }

这是我的xml文件

 <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".BookGalleryActivity">

  <android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

  </android.support.v7.widget.RecyclerView>


  <com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/ad_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center"
    ads:adSize="BANNER"
    ads:adUnitId="ad unit id">

  </com.google.android.gms.ads.AdView>


  <android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|left"
    android:layout_marginLeft="16dp"
    android:layout_marginBottom="64dp"
    android:src="@drawable/dice"/>



</android.support.design.widget.CoordinatorLayout>

0 个答案:

没有答案