Firebase / Admob - 无法加载广告,错误代码为0

时间:2017-04-28 11:31:41

标签: android firebase admob

尝试使用Android Studio在Java Android中设置连接到Firebase的Admob。在应用尝试获取广告后,我得到: "收到广告回复时出现问题。 ErrorCode:0"

我正在使用

MobileAds.initialize(getApplicationContext(), "ca-app-pub-4659004653816xxx~xxxxxxxxxx");

还使用:

    Bundle extras = new Bundle();
    extras.putBoolean("is_designed_for_families", true);

    mAdView = (AdView) findViewById(R.id.adView);
    adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // Emulator
        .tagForChildDirectedTreatment(true)
        .addNetworkExtrasBundle(AdMobAdapter.class, extras)
        .addKeyword("parent")
        .addKeyword("child")
        .build();

    mAdView.setBackgroundColor(Color.TRANSPARENT);
    mAdView.loadAd(adRequest);
    mAdView.bringToFront();

XML包含:

并在xml布局中

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentTop="true"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-465900465381xxxx/xxxxxxxxxx">
</com.google.android.gms.ads.AdView>

我的build.gradle是:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'
        classpath 'com.google.gms:google-services:3.0.0'
    }

}

allprojects {
    repositories {
        jcenter()
    }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "com.kissta.obfusiated"
        minSdkVersion 15
        targetSdkVersion 22
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.google.firebase:firebase-ads:10.2.1'
}
apply plugin: 'com.google.gms.google-services'

0 个答案:

没有答案