【问题标题】:How to show native ads with Google Mobile Ads SDK 20.5.0?如何使用 Google Mobile Ads SDK 20.5.0 展示原生广告?
【发布时间】:2022-01-11 03:34:48
【问题描述】:

我正在尝试在我的项目中展示原生测试广告 (play-services-ads:20.5.0)。我尝试过这种方式并使用相同的错误代码得到不同的错误。无法确定是服务器问题还是我的实现无法满足 SDK 的要求。我等了 2 个多小时(SpinUp Time),但它不起作用。

public class MainActivity extends AppCompatActivity {

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

        MobileAds.initialize(getApplicationContext());
        Log.d("him", "SDK initialized");

        AdLoader adLoader = new AdLoader.Builder(getApplicationContext(), "ca-app-pub-3940256099942544/2247696110")
                .forNativeAd(new NativeAd.OnNativeAdLoadedListener() {
                    @Override
                    public void onNativeAdLoaded(@NonNull NativeAd nativeAd) {
                        Log.d("him", "NativeAdLoaded");

                        NativeTemplateStyle styles = new
                                NativeTemplateStyle.Builder().build();

                        TemplateView template = findViewById(R.id.my_template);
                        template.setStyles(styles);
                        template.setNativeAd(nativeAd);
                    }
                }) .withAdListener(new AdListener() {
                    @Override
                    public void onAdFailedToLoad(@NonNull LoadAdError adError) {
                        // Handle the failure by logging, altering the UI, and so on.

                        Log.d("him", "AdFailedToLoad error is: \n" + adError);
                    }
                })
                .build();

        adLoader.loadAd(new AdRequest.Builder().build());

    }
}

我收到两种类型的错误,一种来自物理设备:

  "Code": 0,
  "Message": "Unable to obtain a JavascriptEngine.",
  "Domain": "com.google.android.gms.ads",
  "Cause": "null",
  "Response Info": {
    "Response ID": "null",

另一个来自模拟器,是这样的:

  "Code": 0,
  "Message": "Internal error.",
  "Domain": "com.google.android.gms.ads",
  "Cause": "null",
  "Response Info": {
    "Response ID": "hu2sYZCLOJO39QP7qIvoBw",
    "Mediation Adapter Class Name": "",
    "Adapter Responses": [
      {
        "Adapter": "com.google.ads.mediation.admob.AdMobAdapter",
        "Latency": 29,
        "Credentials": {},
        "Ad Error": {
          "Code": 0,
          "Message": "Internal error.",
          "Domain": "com.google.android.gms.ads",
          "Cause": "null"
        }
      }

我在使用模拟器时遇到了另一个问题:

Exception thrown while unbinding
java.lang.IllegalArgumentException: Service not registered: lu@bc13fba

提前致谢

【问题讨论】:

    标签: android service admob ads illegalargumentexception


    【解决方案1】:

    请检查您是否在该设备上安装了 adblock。

    请也试试这个 TEMP 解决方案“它可能会有所帮助”:- 在build.gradle 应用级别,将应用ID更改为:

            applicationId "com.google.example.gms.nativeadvancedexample"
    

    让我们知道结果。

    【讨论】:

      【解决方案2】:

      我尝试了另一台设备来测试代码,它运行良好。

      【讨论】:

      • 请将这些添加为 cmets。这不是问题的解决方案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 2016-10-24
      • 1970-01-01
      • 1970-01-01
      • 2022-07-11
      • 2019-09-09
      • 2018-05-12
      相关资源
      最近更新 更多