簡體   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