javaandroidadmobadsbanner-ads

Admob Banner Ads don't display


I don't get an error, they just don't show.

In the manifest I have:

<uses-permission android:name="android.permission.INTERNET" android:maxSdkVersion="28"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission-sdk-23 android:name="android.permission.INTERNET"
    android:maxSdkVersion="28" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_NETWORK_STATE"
    android:maxSdkVersion="28"/>

In the layout I have:

<com.google.android.gms.ads.AdView
    android:id="@+id/publisherAdView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp"
    app:adSize="BANNER"
    app:adUnitId="ca-app-pub-??????????????/????????"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

(I used ? to hide my ads number)

In the Activity I have:

private AdView mPublisherAdView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play_normal);
    MobileAds.initialize(this, "ca-app-pub-?????????????~???????");

    mPublisherAdView = findViewById(R.id.publisherAdView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mPublisherAdView.loadAd(adRequest);

This are my graddle files:

buildscript {

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


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    google()
    jcenter()
    maven {
        url "https://maven.google.com"
    }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

And:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "???????.?????"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 1203
        versionName "1.2.03"
        testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:26.1.0'
//GSON
implementation 'com.google.code.gson:gson:2.8.2'
//RecycleView
implementation 'com.android.support:recyclerview-v7:26.1.0'
//ADS
implementation 'com.google.android.gms:play-services-ads:17.1.1'
}

The thing is that the app uses internet because I can see I consumed X internet data, but the ads doesn't display. I tried everything, I followed the Google tutorials and copied what their webs say but I cant fix it. I looks like adds load because it takes a little to load the activity, and it didn't do so before, but the ad is invisible or something. I'm using an smartphone with API 26 so it's not the API level.


Solution

  • The problem was Admob, for some reason my account wasn't validated, and that's why I though the problem was in the code, not in Admob.