1

I created an account at Admob since a month, and i added payment method since 2 days ago. a test device showing ads successfully. but other devices don't show any thing with error code:3

Ads: Ad failed to load : 3

public class MainActivity extends AppCompatActivity implements RewardedVideoAdListener {
    private AdView adView;
    private Button onePlayer, twoPlayer, exit;
    private InterstitialAd mInterstitialAd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MobileAds.initialize(this, getString(R.string.app_id));
        MobileAds.initialize(this, initializationStatus -> {

        });
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId(getString(R.string.instruction));
        mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice("my-device-id").build());
        mInterstitialAd.setAdListener(InterstitialListener);
        adView = findViewById(R.id.adView);
        adView.loadAd(new AdRequest.Builder().addTestDevice("my-device-id").build());
        adView.setAdListener(adListener);
   }
}

and i created a listener for InterstitialAd

private AdListener InterstitialListener = new AdListener() {
        @Override
        public void onAdLoaded() {
            // Code to be executed when an ad finishes loading.
            mInterstitialAd.show();
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            // Code to be executed when an ad request fails.
            Toast.makeText(getApplicationContext(), "errorCode " + errorCode + "", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onAdOpened() {
            // Code to be executed when the ad is displayed.
        }

        @Override
        public void onAdClicked() {
            // Code to be executed when the user clicks on an ad.
        }

        @Override
        public void onAdLeftApplication() {
            // Code to be executed when the user has left the app.
        }

        @Override
        public void onAdClosed() {
            // Code to be executed when the interstitial ad is closed.
        }
    };

and this is banner xml:

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner">
</com.google.android.gms.ads.AdView>

Note: the app doesn't uploaded to store yet!

how can i fix this problem?

aghiad odeh
  • 39
  • 1
  • 8

2 Answers2

1

This answer might help someone in future. I had the same problem. Ads were working fine in test devices. But in real device it did not display any ad.

I published my app to google play and downloaded it. In the app downloaded from google play, Ads are showing fine. I did not make any changes to the code

I am not sure why this happens, it's kind of black box.

Some answers in stack overflow says no need to publish app for showing ads. But it was not true in my case.

Anand Raj
  • 435
  • 2
  • 8
0

Your code seems fine. Are you using this test unit ID for your banner?

ca-app-pub-3940256099942544/6300978111

Or are you using the one from your AdMob account?

rob_1982
  • 13
  • 5
  • unfortunately, i didn't understand, what you mean? about test unit ID for your banner – aghiad odeh Mar 11 '20 at 13:49
  • In your banner xml file there is a value called ads:adUnitId="@string/banner", that get's it's value from a string resource named "banner". You can check the existing banner unit ID in strings.xml file and see if the value is **ca-app-pub-3940256099942544/6300978111**. If not, you can try to use it to see if it works. – rob_1982 Mar 11 '20 at 14:15
  • the unit ID in strings.xml is the same my banner id in admob the problem not only the banner ad all ads not showing (InterstitialAd also give error code: 3),, the value of "@string/banner" is different of **ca-app-pub-3940256099942544/6300978111.** – aghiad odeh Mar 11 '20 at 17:47