2

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?

Theo.b
  • 68
  • 1
  • 8
  • @theo-b were you able to solve this? – Manohar Reddy Poreddy Mar 05 '19 at 02:55
  • 1
    @ManoharReddyPoreddy I solved it. The problem was that inside every Activitiy I did not initialize my Ads with my personal Ads ID created in AdMob but with the testID provided by Google. I inserted MobileAds.initialize("....my AdBanner ID...."); in every Activity – Theo.b Mar 05 '19 at 15:24
  • @theo-b , thanks for the reply, mine too was a code bug, copy-pasted code from the internet, which I fixed, wrote here: https://stackoverflow.com/a/55001725/984471 – Manohar Reddy Poreddy Mar 06 '19 at 00:25

1 Answers1

0

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

Ehsan Rosdi
  • 835
  • 9
  • 18
  • Thanks ehsan-rosdi, my code was Cordova Admob app, and it had only one location to change in js file, fixed it like this: https://stackoverflow.com/a/55001725/984471 – Manohar Reddy Poreddy Mar 06 '19 at 00:28