来自Admob的实时广告未显示

问题描述 投票:1回答:2

昨天我在Admob和我的应用上创建了一个帐户,测试广告运行良好,但实时(真实)广告没有显示。当我添加onFaildToLoad事件时,它返回INTERNAL_ERROR。那么有什么解决方案吗?在Play商店上传应用以获取实时广告是否很重要?

这是我的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="208dp"
            android:text="login" />

        <EditText
            android:id="@+id/editText"
            android:layout_width="297dp"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="183dp"
            android:ems="10"
            android:inputType="textPassword" />
    </RelativeLayout>
    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-8140603259324677/7029410922">
    </com.google.android.gms.ads.AdView>
</LinearLayout>

这是我的java代码:

package com.example.moamen.webbrowser;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

import static com.google.android.gms.ads.AdRequest.ERROR_CODE_INTERNAL_ERROR;
import static com.google.android.gms.ads.AdRequest.ERROR_CODE_INVALID_REQUEST;
import static com.google.android.gms.ads.AdRequest.ERROR_CODE_NETWORK_ERROR;
import static com.google.android.gms.ads.AdRequest.ERROR_CODE_NO_FILL;

public class LoginActivity extends AppCompatActivity {
    Button mButton;
    EditText mEditText;
    private AdView mAdView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        try {
            mAdView.loadAd(adRequest);
        } catch (Exception e) {
            e.printStackTrace();
        }
        mEditText = (EditText) findViewById(R.id.editText);
        mButton = (Button) findViewById(R.id.button);
        final String passA= "facebook";
        final String passB = "moa";
        // Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
        MobileAds.initialize(this, "ca-app-pub-8140603259324677~4251010820");
        mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String text = mEditText.getText().toString().trim();
                if (text.equals(passA)){
                    Intent intent = new Intent(LoginActivity.this,MainActivity.class);
                    intent.putExtra("website","https://www.facebook.com/");
                    startActivity(intent);
                }else if (text.equals(passB) ){
                    Intent intent = new Intent(LoginActivity.this,MainActivity.class);
                    intent.putExtra("website","https://www.google.com/");
                    startActivity(intent);
                }else {
                    Toast.makeText(LoginActivity.this, "Password is incorrect", Toast.LENGTH_SHORT).show();
                }
            }
        });
        mAdView.setAdListener(new AdListener(){
            @Override
            public void onAdFailedToLoad(int errorCode) {
                // Code to be executed when an ad request fails.
                if (errorCode == ERROR_CODE_INTERNAL_ERROR){
                    Toast.makeText(LoginActivity.this,"ERROR_CODE_INTERNAL_ERROR",Toast.LENGTH_SHORT).show();
                }else if (errorCode == ERROR_CODE_INVALID_REQUEST){
                    Toast.makeText(LoginActivity.this,"ERROR_CODE_INVALID_REQUEST",Toast.LENGTH_SHORT).show();
                }else if (errorCode == ERROR_CODE_NETWORK_ERROR){
                    Toast.makeText(LoginActivity.this,"ERROR_CODE_NETWORK_ERROR",Toast.LENGTH_SHORT).show();
                }else if (errorCode == ERROR_CODE_NO_FILL){
                    Toast.makeText(LoginActivity.this,"ERROR_CODE_NO_FILL",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }


}

这是我的gardle.build文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.drshimaa.webbrowser"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        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'])
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0-rc02'
    implementation 'com.google.android.gms:play-services-ads:15.0.0'
    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'
}
allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

the error

test ads is working well

android admob runtime-error ads internals
2个回答
0
投票

如果您正在获得TestAds,那么您的实现是正确的。

更改您的包ID并检查


0
投票

如果您最近创建了一个AdUnit,那么您必须等待一段时间让AdUnit获得激活...

© www.soinside.com 2019 - 2024. All rights reserved.