AdMob广告未在Android Studio上展示

时间:2018-01-13 03:42:48

标签: android admob

我很难将admob广告添加到Android应用中并且不断收到错误消息:function deleteButton(id) { var dBtn1 = "<div data-dojo-type='dijit/form/Button'>"; var dBtn2 = "<img src='delete.png' onclick='javascript:removeItem()' alt='" + id + "'"; dBtn = dBtn1 + dBtn2 + " width='18' height='18'></div>"; return dBtn; } 后跟There was a problem getting an ad response. ErrorCode: 0。所以我直接从教程中复制了代码,但仍然得到了同样的错误。我正在使用本教程中android studio提供的所有内容:https://developers.google.com/admob/android/quick-start

这是xml:

Failed to load ad: 0

活动:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="michaelsinn.contact.gmail.com.testads.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <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_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
    </com.google.android.gms.ads.AdView>

</android.support.constraint.ConstraintLayout>

感谢任何和所有帮助!谢谢

1 个答案:

答案 0 :(得分:0)

试试这个。

AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
Toast.makeText(getApplicationContext(),"Ad Loaded",Toast.LENGTH_SHORT).show();
        // Code to be executed when an ad finishes loading.
    }

    @Override
    public void onAdFailedToLoad(int errorCode) {
Toast.makeText(getApplicationContext(),"Ad Failed to load",Toast.LENGTH_SHORT).show();
        // Code to be executed when an ad request fails.
    }

    @Override
    public void onAdOpened() {
Toast.makeText(getApplicationContext(),"Ad Opened",Toast.LENGTH_SHORT).show();
        // Code to be executed when an ad opens an overlay that
        // covers the screen.
    }

    @Override
    public void onAdLeftApplication() {
Toast.makeText(getApplicationContext(),"Ad Left Application",Toast.LENGTH_SHORT).show();
        // Code to be executed when the user has left the app.
    }

    @Override
    public void onAdClosed() {
Toast.makeText(getApplicationContext(),"Ad Closed",Toast.LENGTH_SHORT).show();
        // Code to be executed when when the user is about to return
        // to the app after tapping on an ad.
    }
});