简体   繁体   English

Admob 横幅广告不显示

[英]Admob Banner Ads don't display

I don't get an error, they just don't show.我没有收到错误,他们只是不显示。

In the manifest I have:在清单中,我有:

<uses-permission android:name="android.permission.INTERNET" android:maxSdkVersion="28"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission-sdk-23 android:name="android.permission.INTERNET"
    android:maxSdkVersion="28" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_NETWORK_STATE"
    android:maxSdkVersion="28"/>

In the layout I have:在布局中,我有:

<com.google.android.gms.ads.AdView
    android:id="@+id/publisherAdView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp"
    app:adSize="BANNER"
    app:adUnitId="ca-app-pub-??????????????/????????"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

(I used ? to hide my ads number) (我用 ? 来隐藏我的广告编号)

In the Activity I have:在活动中,我有:

private AdView mPublisherAdView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play_normal);
    MobileAds.initialize(this, "ca-app-pub-?????????????~???????");

    mPublisherAdView = findViewById(R.id.publisherAdView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mPublisherAdView.loadAd(adRequest);

This are my graddle files:这是我的graddle文件:

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    google()
    jcenter()
    maven {
        url "https://maven.google.com"
    }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

And:和:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "???????.?????"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 1203
        versionName "1.2.03"
        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'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:26.1.0'
//GSON
implementation 'com.google.code.gson:gson:2.8.2'
//RecycleView
implementation 'com.android.support:recyclerview-v7:26.1.0'
//ADS
implementation 'com.google.android.gms:play-services-ads:17.1.1'
}

The thing is that the app uses internet because I can see I consumed X internet data, but the ads doesn't display.问题是该应用程序使用互联网,因为我可以看到我消耗了 X 互联网数据,但没有显示广告。 I tried everything, I followed the Google tutorials and copied what their webs say but I cant fix it.我尝试了所有方法,我遵循了 Google 教程并复制了他们的网站上所说的内容,但我无法修复它。 I looks like adds load because it takes a little to load the activity, and it didn't do so before, but the ad is invisible or something.我看起来好像是增加了负载,因为加载活动需要一点时间,之前没有这样做,但是广告是不可见的什么的。 I'm using an smartphone with API 26 so it's not the API level.我使用的是带有 API 26 的智能手机,所以它不是 API 级别。

You have to build the addRequest properly using AdListener 你必须建立addRequest正确使用AdListener

mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build();
mAdView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
      if (mAdView.getVisibility() == View.GONE) {
            mAdView.setVisibility(View.VISIBLE);
       }
     }
  });
mAdView.loadAd(adRequest);

And the XML for Adview is 而Adview的XML是

<LinearLayout
    android:id="@+id/ad_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerInParent="true"
    >
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        android:visibility="gone"
        ads:adUnitId="@string/banner_ad_id">
    </com.google.android.gms.ads.AdView>
</LinearLayout>

Its better to place your banner id inside your strings file. 最好将banner id放在字符串文件中。

问题是Admob,出于某种原因,我的帐户未通过验证,这就是为什么我虽然在代码中而不是在Admob中导致了问题。

Your account may be not approved.您的帐户可能未获批准。 You can find out what the error is using:您可以找出错误使用的是什么:

@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
    super.onAdFailedToLoad(loadAdError);
    Log.d("ERROR",loadAdError.toString());
}

After you know your error you can fix it here: https://support.google.com/admob/answer/9905175知道错误后,您可以在此处修复它: https : //support.google.com/admob/answer/9905175

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

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