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

查看:28
本文介绍了“无广告配置."尝试加载广告时的 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() in 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();
                    }

推荐答案

修复它并且它工作.

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

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.

启用测试广告.有两种方法:您可以使用上面链接上提供的谷歌广告单元 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("Your device Id will be here");

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天全站免登陆