Admob 横幅未显示

Ale*_*lex 5 android banner admob

我的 admob 横幅没有显示,我已经阅读了此处的指南 https://firebase.google.com/docs/admob/android/quick-start

主要活动

private AdView mAdView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544/6300978111");
    mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
}
Run Code Online (Sandbox Code Playgroud)

布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.myapplication.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

    <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_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
    </com.google.android.gms.ads.AdView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

在我的清单中,我有这个权限

<uses-permission android:name="android.permission.INTERNET" />
Run Code Online (Sandbox Code Playgroud)

项目摇篮

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

应用程序梯度

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.google.firebase:firebase-ads:10.0.1'
    compile 'com.google.firebase:firebase-core:10.0.1'
    testCompile 'junit:junit:4.12'
}



apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)

日志

01-31 20:44:49.586 3556-3556/? D/ucsBai_ConnectionManager: mPackageReceiver Action android.intent.action.PACKAGE_ADDED
01-31 20:44:58.836 19607-19607/com.example.myapplication I/FA: App measurement is starting up, version: 10084
01-31 20:44:58.836 19607-19607/com.example.myapplication I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
01-31 20:44:58.836 19607-19607/com.example.myapplication D/FA: Debug-level message logging enabled
01-31 20:44:58.836 19607-19607/com.example.myapplication D/FA: AppMeasurement singleton hash: 23949389
01-31 20:44:58.846 19607-19607/com.example.myapplication V/FA: Collection enabled
01-31 20:44:58.846 19607-19607/com.example.myapplication V/FA: App package, google app id: com.example.myapplication, 1:665936977222:android:13c3c6a65bcbec53
01-31 20:44:58.846 19607-19607/com.example.myapplication I/FA: To enable faster debug mode event logging run:
                                                                 adb shell setprop debug.firebase.analytics.app com.example.myapplication
01-31 20:44:58.906 19607-19607/com.example.myapplication V/FA: Registered activity lifecycle callback
01-31 20:44:58.916 19607-20434/com.example.myapplication V/FA: Using measurement service
01-31 20:44:58.916 19607-20434/com.example.myapplication V/FA: Connecting to remote service
01-31 20:44:59.816 19607-20434/com.example.myapplication V/FA: Connection attempt already in progress
01-31 20:45:00.116 19607-20434/com.example.myapplication D/FA: Connected to remote service
01-31 20:45:00.116 19607-20434/com.example.myapplication V/FA: Processing queued up service tasks: 2
01-31 20:45:05.156 19607-20434/com.example.myapplication V/FA: Inactivity, disconnecting from the service
Run Code Online (Sandbox Code Playgroud)

Mil*_*yas 2

您输入广告单元 ID,而不是应用程序 ID。

MobileAds.initialize(getApplicationContext(), here your app id will come );
Run Code Online (Sandbox Code Playgroud)

这是您的广告 ID,两者不同,只需更改上面的代码并输入应用程序 ID 而不是您的广告单元 ID。

这是您的广告单元 ID

ca-app-pub-3940256099942544/6300978111
Run Code Online (Sandbox Code Playgroud)

希望这会起作用。干杯!