2017-02-01 3 views
3

Mein admob Banner nicht angezeigt wird, ich habe hier durch die Führung gefunden https://firebase.google.com/docs/admob/android/quick-startAdmob Banner zeigt nicht bis

MainActivity

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); 
} 

Layout-

<?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> 

In meinem Manifest gegangen Ich habe diese Erlaubnis

<uses-permission android:name="android.permission.INTERNET" /> 

Projekt Gradle

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 
} 

App gradle

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' 

Log

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 
+0

Verwenden Sie Emulator? zum Prüfen ? –

+0

Ich habe versucht, ein Gerät und einen Emulator zu verwenden – Alex

+0

Haben Sie versucht, es programmgesteuert zu tun? – Vyacheslav

Antwort

1

Sie legen Ihren Anzeigenblock-ID instend von ID App.

MobileAds.initialize(getApplicationContext(), here your app id will come); 

Und das ist Ihre Anzeige ID beide sind verschieden nur über Code ändern und App-ID anstelle Ihrer Anzeigenblock-ID setzen.

Dies ist Ihr Anzeigenblock-ID

ca-app-pub-3940256099942544/6300978111 

Hope this Werke. Prost!

+0

Das Banner wird immer noch nicht angezeigt – Alex

+0

Haben Sie es auch in anderen Geräten getestet? und kannst du bitte überprüfen, ob das Internet eingeschaltet ist oder nicht? –

+0

ok ich habe dein Problem Ich werde meinen vorhandenen Code bearbeiten bitte überprüfen –

2

Öffnen Sie zuerst die https://apps.admob.com/ und dann Ihre Anwendung von dort nun die Monetisieren Tab wählen von dort nun den Befehl Ansicht Setup

enter image description here

erweitern

Hier müssen Sie Ihre ID App setzen

MobileAds.initialize(getApplicationContext(), "ca-app-pub-1440645979698474~6985293144"); // replace with yours 

Und für xml enter image description here

Wählen Sie aus Adunits

<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-1440645979698474/3892225947"> 

Ersetzen Sie mit Ihrer adUnitId und Sie sind fertig.

Verwandte Themen