简体   繁体   English

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

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

I'm trying to show native test ads on my project (play-services-ads:20.5.0).我正在尝试在我的项目中展示原生测试广告(play-services-ads:20.5.0)。 I tried this way and get different errors with the same error code.我尝试过这种方式并使用相同的错误代码得到不同的错误。 Can't really figure out is it a server issue or my implementation can't fulfill SDK's requirements.无法确定是服务器问题还是我的实现无法满足 SDK 的要求。 I waited more than 2 hours (SpinUp Time) but it doesn't work.我等了 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());

    }
}

I'm getting two types error one is from physical device which is this:我收到两种类型的错误,一种来自物理设备,它是:

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

And another is from emulator, which is this:另一个来自模拟器,就是这样:

  "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"
        }
      }

I got another issue while using emulator which is here:我在使用模拟器时遇到了另一个问题:

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

Thanks in advance提前致谢

I tried another device to test the code and it worked perfectly.我尝试了另一个设备来测试代码,它运行良好。

Please check if you have an adblock installed on that device.请检查您是否在该设备上安装了 adblock。

Please also try this TEMP solution "it might help":- in build.gradle app level, change the app id to:还请尝试此TEMP解决方案“它可能会有所帮助”:- 在build.gradle应用程序级别中,将应用程序 ID 更改为:

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

and let's know if the result.让我们知道结果。

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

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