0

I swear i have tried many many ways to resolve this problem, but i'ml tired and it's saturday and i'm still workin on only this problem...

Please help!!

  • I registred my device as a test device
  • My admob account is validated a few weeks ago
  • Google test ads work fine on the same device
  • Tested with two real devices without success

Here is my myactivity.java:

       MobileAds.initialize(this, new OnInitializationCompleteListener() {
            @Override
            public void onInitializationComplete(InitializationStatus initializationStatus) {}
        });
        if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
        } else {
            Toast.makeText(this, "Ad did not load", Toast.LENGTH_SHORT).show();
        }
        // Create the InterstitialAd and set the adUnitId.
        mInterstitialAd = new InterstitialAd(this);
        // Defined in res/values/strings.xml
        mInterstitialAd.setAdUnitId(AD_UNIT_ID);
        RequestConfiguration configuration = new RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("BDB.....")).build();
        MobileAds.setRequestConfiguration(configuration);

        mInterstitialAd .setAdListener(
                new AdListener() {
                    @Override
                    public void onAdLoaded() {
                        Toast.makeText(MainActivity.this, "onAdLoaded()", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onAdFailedToLoad(LoadAdError loadAdError) {
                        String error =
                                String.format(
                                        "domain: %s, code: %d, message: %s",
                                        loadAdError.getDomain(), loadAdError.getCode(), loadAdError.getMessage());
                        Toast.makeText(
                                MainActivity.this, "onAdFailedToLoad() with error: " + error, Toast.LENGTH_SHORT)
                                .show();
                    }

                    @Override
                    public void onAdClosed() {
                        //startGame();
                    }
                });


        if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
        } else {
            Toast.makeText(this, "Ad did not load", Toast.LENGTH_SHORT).show();
        }

And the gradle of the app :

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"
    defaultConfig {
        applicationId "com....."
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true 
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    useLibrary 'org.apache.http.legacy'
}

dependencies {

    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.brewtab.json:json:1.0.0'
    implementation 'com.android.volley:volley:1.1.0'

    implementation 'com.google.firebase:firebase-ads:19.7.0'
    implementation 'com.google.firebase:firebase-auth:20.0.2'
    implementation 'com.google.android.gms:play-services-ads:19.7.0'
    implementation 'androidx.appcompat:appcompat:1.2.0'

}
Dr Mido
  • 2,414
  • 4
  • 32
  • 72
Eff
  • 3
  • 2

1 Answers1

0

i use this simplified solution for my interstitial ads and it always works but make sure you use a testing unit id

    //variables
    private InterstitialAd interstitialAd;
    
    //place this in your oncreate method
    public void loadAD()
    {
        interstitialAd= new InterstitialAd(this);
        interstitialAd.setAdUnitId(getString(R.string.ad_id));
        AdRequest adRequest = new AdRequest.Builder().build();
        interstitialAd.loadAd(adRequest);
    }
    //place this method where you want your ad to load (ex: onclick of a button)
    public void showAd()
    {
            if (interstitialAd.isLoaded()) 
            {
                interstitialAd.show();
                System.out.println("add shown");
            } 
            else 
            {
                Log.d("TAG", "The interstitial wasn't loaded yet.");
            }
    }
Bilal Rammal
  • 814
  • 8
  • 14
  • thanks bilal. But it seems that google admob has upated the way to ad ads... And your way doesn't work for me "api 30" – Eff Feb 13 '21 at 14:12
  • Please any help would be appreciated. It gets me crazy. – Eff Feb 13 '21 at 19:23
  • i am using the following method currently on the latest api make sure you initialized the mobileads before adding my code – Bilal Rammal Feb 16 '21 at 12:09
  • Ok thank you. This works fine actually with the google ID AD. So I have changed it to ly real pub ID and published it into play store. Hope it will work.... I hope I hope.... many thanks anyway. Very nice – Eff Feb 17 '21 at 22:38
  • yes it should work fine i have 3 production apps with this implementation and all ads are working fine , good luck – Bilal Rammal Feb 17 '21 at 22:41