Search code examples
androidadmobads

Admob shows only test Ads instead of real Ads


I have developed an app that use AdMob for showing ads. The problem is that test ads are showing instead of real ads in API 24 and above, while work properly in API 23 and below. I do not know which is the problem but I can assure that : 1. I do not implement .addTestDevice 2. I use my my apps unitID and not the test ID

I attach my onCreate method :

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_edit_text_note);
    //Δημιουργία διαφημίσεων banner

    //Φόρτωση διαφημίσεων banner
    mAdView = findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

and my layout file is :

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:contentDescription="@string/advertisement"
    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-4565************/27********">
</com.google.android.gms.ads.AdView>

my build.gradle :

        apply plugin: 'com.android.application'

    android {
        compileSdkVersion 27
        buildToolsVersion '28.0.3'
        defaultConfig {
            applicationId "com.sebastian_pa.sebastian_v2"
            minSdkVersion 16
            targetSdkVersion 27
            versionCode 4
            versionName "1.2"
            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'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:27.0.1'
    implementation 'com.android.support:design:27.0.1'
    testImplementation 'junit:junit:4.12'
    implementation 'com.google.android.gms:play-services-ads:17.0.0'

}

Does anyone knows why this is happening?


Solution

  • There are 3 places that you need to change from your test id to your own id.

    1. In manifest file
    2. In you initialize code
    3. In your xml file

    From your post, I can see you only did the last one.

    For step 1&2, have a look here https://developers.google.com/admob/android/quick-start?hl=en-US#import_the_mobile_ads_sdk

    For step 3 have a look here https://developers.google.com/admob/android/banner?hl=en-US