“无广告配置".在 onAdFailedToLoad() 方法上尝试加载广告时 [英] "No Ad Config." on onAdFailedToLoad() Method While trying to Load Ads

查看:27
本文介绍了“无广告配置".在 onAdFailedToLoad() 方法上尝试加载广告时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的应用加载插页式广告.每当我尝试加载这些广告时,都会收到一条错误消息,提示无广告配置".来自域com.google.android.gms.ads".

I am trying to load interstitial advertisements for my app. Whenever I try to load these ads I get a Error saying "No Ads Config" from Domain "com.google.android.gms.ads".

代码如下:

我的 AndroidManifest.xml

My AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ayush.torch">


    <application

        android:allowBackup="true"
        android:icon="@drawable/ic_ico"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".main">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="i_have_put_my_app_id_here"/>
     
    </application>

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />

</manifest>

onCreate() 在 main.java 中

onCreate() in main.java

        
        // Creating the InterstitialAd and setting the adUnitId.
        interstitialAd = new InterstitialAd(this);
        interstitialAd.setAdUnitId("i have also put my interstitial ad id here");


       interstitialAd.setAdListener(new AdListener() {
           @Override
           public void onAdLoaded() {
               Toast.makeText(main.this, "Ad Loaded", Toast.LENGTH_SHORT).show();
           }

           @Override
           public void onAdFailedToLoad(LoadAdError loadAdError) {
               String error = String.format("domain: %s, code: %d, message: %s", loadAdError.getDomain(), loadAdError.getCode(), loadAdError.getMessage());
               Toast.makeText(main.this, "onAdFailedToLoad() with error: " + error, Toast.LENGTH_SHORT).show();
           }
       });

当我在 on 函数中加载我的广告时,它给我错误无广告配置".

When I load my ad in a on function it gives me error "No Ad Config."

                    Log.d("[Ads]","Ad Load State For on(): " + interstitialAd.isLoaded());
                    if (interstitialAd.isLoaded()) 
                    {
                        interstitialAd.show();
                    }

推荐答案

Fixed It and it works.

Fixed It and it works.

从谷歌找到了一个资源.它消除了我所有的疑虑.有关测试广告资源,请点击我

Found a resource from google. And It cleared all my doubts. For Test Ad Resource Click Me

广告有两种作用.

  1. 应用正在开发中.
  2. 应用正在生产中.


场景 1:当应用程序处于开发阶段

对于这种情况,我们需要使用测试广告.Admob 和com.google.android.gms.ads"由于错误印象,不允许用户在开发阶段使用广告.

For this case, we need to use Test Advertisements. Admob and "com.google.android.gms.ads" doesnt allow user to use Advertisements in Development Phase due to false impressions.

启用测试广告.有两种方式:您可以使用链接 adove 上提供的谷歌广告单元 ID.或者您可以使用自己的广告单元 ID,但您需要将您的设备注册为测试设备并使用您自己的请求配置.这是一个简单的例子:搜索您的设备 ID"在Logcat"

To enable Test Advertisement. There are two ways: You can either use google ad unit id's which are available on the link adove. Or You can use your own ad unit id, but you will be needing to register your device as a test device and use your own request configuration. Here is a simple Example: Search for your "Device Id" In "Logcat"

它看起来像

I/ADS:使用请求的配置......Arrays.asList(您的设备 ID 将在此处");

I/ADS: Use Requested Configuration......Arrays.asList("Your device Id will be here");

然后复制粘贴这个(我能读懂你的想法..)

Then Just Copy Paste This(i can read your mind..)

// Change your Id
RequestConfiguration configuration = new RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("your device id should go here")).build();
MobileAds.setRequestConfiguration(configuration);

现在只需加载广告,它就会弹出.恭喜.:)

Now just load the ad and it will pop up. Congratz. :)

场景 2:应用正在生产中

这是非常简单的部分...

This is pretty simple part...

  1. 只需从代码中删除 .setTestDeviceIds(Arrays.asList("your device id should go here")) 部分...
  2. 将您的 AdMob 应用关联到 PlayStore.[你的应用发布了吗?是的……是的……然后……]
  3. 只需选择广告.
  4. 并检查是否在 Play 控制台的应用设置中启用了广告.
  5. 它现在应该可以工作了.恭喜.

这篇关于“无广告配置".在 onAdFailedToLoad() 方法上尝试加载广告时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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