AdMob-广告未显示-错误2 [英] AdMob - Ad not displayed - Error 2

查看:76
本文介绍了AdMob-广告未显示-错误2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个具有两个版本的android应用程序。一个带有Ad。还有一个没有广告。我已经成功将 AdMob 集成到了应用程序中。但广告不会在屏幕上显示。

I am building an android application that has two versions.One with Ad. and one with out Ad. . I've successfully integrated the AdMob in the application. but the Ads are not getting displayed on the screen.

这是我的

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    productFlavors{
        free{
            applicationId "com.myapp"
            buildConfigField "boolean","IS_PAID_VERSION", "false"
        }

        paid{
            applicationId "com.myapp.paid"
            buildConfigField "boolean","IS_PAID_VERSION", "true"
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.google.android.gms:play-services-ads:8.4.0'
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    tools:context="com.myapp.activities.AdTestActivity">

    <com.google.android.gms.ads.AdView
        android:id="@+id/ad_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/ad_unit_id" />

</RelativeLayout>

AdTestActivity.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.myapp.R;

public class AdTestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ad_test);

        final AdView adView = (AdView) findViewById(R.id.ad_view);
        final AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice("A144A6A159A94CC77CE70EC1A874B93A") //My test device 1
                .addTestDevice("8477FA9B6C105C84897FC2717E19A548")  //My test device 2
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .build();

        adView.loadAd(adRequest);

    }
}

广告没有显示屏幕上, logcat 表示...

The ad is no getting displayed on the screen, and the logcat says...

I/Ads: Starting ad request.
02-12 00:24:41.381 15472-15493/com.myapp W/Ads: There was a problem getting an ad response. ErrorCode: 2
02-12 00:24:41.382 15472-15472/com.myapp I/Ads: Scheduling ad refresh 60000 milliseconds from now.
02-12 00:24:41.382 15472-15472/com.myapp W/Ads: Failed to load ad: 2

PS:我的互联网连接良好,有效的 AdUnitId 。我的设备中没有任何 AdBlock 应用程序。我还阅读了有关此问题的所有SO主题,但没有一个主题对我有用。

PS: I've a good internet connection and valid AdUnitId. I don't have any kind of AdBlock applications in my device. I've also read all SO threads about this problem, but none of them worked for me.

我在这里做错了什么? :(

What am i doing wrong here ? :(

推荐答案

我遇到了同样的问题,并通过将Google Play服务更新到手机上的最新版本来解决此问题。也许尝试从Play商店对其进行更新。

I had the same issue and I fixed it by updating Google Play Services to the latest version on my mobile. So maybe try updating it from Play Store.

这篇关于AdMob-广告未显示-错误2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆