【问题标题】:Admob shows only test Ads instead of real AdsAdmob 仅显示测试广告而非真实广告
【发布时间】:2018-12-03 21:41:58
【问题描述】:

我开发了一个使用 AdMob 来展示广告的应用。问题是在 API 24 及更高版本中显示测试广告而不是真实广告,而在 API 23 及更低版本中正常工作。 我不知道是哪个问题,但我可以保证: 1.我没有实现.addTestDevice 2. 我使用我的应用 unitID 而不是测试 ID

我附上了我的 onCreate 方法:

@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);

我的布局文件是:

<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>

我的 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'

}

有人知道为什么会这样吗?

【问题讨论】:

  • @theo-b 你能解决这个问题吗?
  • @ManoharReddyPoreddy 我解决了。问题在于,在每个 Activitiy 中,我都没有使用在 AdMob 中创建的个人广告 ID 来初始化我的广告,而是使用 Google 提供的 testID。我插入了 MobileAds.initialize("....my AdBanner ID....");在每个活动中
  • @theo-b ,感谢您的回复,我的也是一个代码错误,从互联网上复制粘贴的代码,我已修复,在这里写道:stackoverflow.com/a/55001725/984471

标签: android admob ads


【解决方案1】:

您需要将 3 个地方从您的测试 ID 更改为您自己的 ID。

  1. 在清单文件中
  2. 在你初始化代码时
  3. 在您的 xml 文件中

从你的帖子中,我可以看到你只做了最后一个。

第 1 步和第 2 步,请看这里https://developers.google.com/admob/android/quick-start?hl=en-US#import_the_mobile_ads_sdk

第 3 步请看这里https://developers.google.com/admob/android/banner?hl=en-US

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-01
相关资源
最近更新 更多