简体   繁体   English

Admob在Android中显示测试广告,但不显示真实广告?

[英]Admob shows Test ads but not real ads in android?

I'm using AdMob for showing android ads. 我正在使用AdMob展示Android广告。 The test ads are working fine but real ads are not shown. 测试广告运行正常,但未展示真实广告。 Also, I've got an issue with real interstitial ads and banner ads both are not working.Here is my code : 另外,真正的插页式广告横幅广告都无法正常工作,这是我的代码:

banner_ads.xml banner_ads.xml

  <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp">

        <com.google.android.gms.ads.AdView 
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-3940256099942544/6300978111">

            <!-- i have used a test ads over here -->

        </com.google.android.gms.ads.AdView>


    </RelativeLayout>

MainActivity.java MainActivity.java

private AdView mAdView;
AdView = fragView.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

<!--for interstitial -->
InterstitialAd mInterstitialAd;
mInterstitialAd = new InterstitialAd(getApplicationContext());
// i have used a test id
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());

How to change my code so that real-time ads also appear? 如何更改我的代码,以便同时显示实时广告?

its an improvement by Android Studio 3.0. 它是Android Studio 3.0的改进。

If you run the app to other device admob will start serving real ads 如果您在其他设备上运行该应用,则admob将开始投放实际的广告

Edit Note: Your code is ok but you copied test ad code from google website that is why you are getting test ad. 修改 说明:您的代码还可以,但是您从Google网站复制了测试广告代码,这就是为什么要获取测试广告。 To show real ad you need to generate ad code from your google admob account. 要显示真实广告,您需要从您的Google admob帐户生成广告代码。

Try this for InterstitialAd because you dont written mInterstitial.show(); 对于InterstitialAd可以尝试使用此方法,因为您没有编写mInterstitial.show(); in your code 在你的代码中

Like this 像这样

public void inrequestadd() {
    mInterstitial = new InterstitialAd(MainActivity.this);
    mInterstitial.setAdUnitId(getString(
            R.string.INTRESTITIAL_ID));
    mInterstitial.loadAd(new AdRequest.Builder().build());
    mInterstitial.setAdListener(new AdListener() {

        @Override
        public void onAdClosed() {
            super.onAdClosed();

        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            super.onAdFailedToLoad(errorCode);

        }

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            if (mInterstitial.isLoaded()) {
                mInterstitial.show();
            }
        }
    });
}

Last week, i have faced the same situation. 上周,我面临着同样的情况。 Please review the steps. 请查看步骤。

1_ be sure to use correct publisher and banner id. 1_确保使用正确的发布者和横幅ID。 I dont see publisher id in your code, please visit admob get started page 我的代码中没有看到发布商ID,请访问admob入门页面

2_ what is the error? 2_什么是错误? you can find it out in logcat. 您可以在logcat中找到它。 Or you can implement adlistener to your code and print it like this; 或者,您可以在代码中实现adlistener并按如下所示进行打印;

mAdView.setAdListener(new AdListener() {

    @Override
    public void onAdFailedToLoad(int errorCode) {
        // log the error code
    }
});

3_if you get error code =0 3_如果您得到错误代码= 0

3.a_some blogs say that; 3.a_some博客这么说; this happens when you create new ad in admob, sometimes it takes 1-2 hours to be worked. 当您在admob中制作新广告时,就会发生这种情况,有时需要1-2个小时才能完成。 So please wait and try again later. 因此,请稍候,然后重试。

3.b_(this is my situation) i dont know the reason but google banned my package name, so in this situation, your application never be allowed to show any advertisement. 3.b_(这是我的情况)我不知道原因,但是Google禁止了我的软件包名称,因此在这种情况下,您的应用程序永远都不允许显示任何广告。 Just change your packege name and everything work fine. 只需更改您的Packege名称,一切正常。 To check this situation, create new sample project and than copy your admob codes. 要检查这种情况,请创建新的示例项目,然后复制您的admob代码。

您在XML和Java文件中都设置了adUnit,请避免同时在java或xml文件中同时设置adUnit。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM