繁体   English   中英

如何使用 Google Mobile Ads SDK 20.5.0 展示原生广告?

[英]How to show native ads with Google Mobile Ads SDK 20.5.0?

我正在尝试在我的项目中展示原生测试广告(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

提前致谢

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

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

还请尝试此TEMP解决方案“它可能会有所帮助”:- 在build.gradle应用程序级别中,将应用程序 ID 更改为:

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

让我们知道结果。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM