智能横幅加载到全屏尺寸

时间:2019-07-19 08:40:52

标签: android admob ads

智能横幅广告加载适应全屏尺寸的广告正在加载,如下图enter image description here

如何解决此问题

在智能横幅广告中加载视频时

我在最新的fcm广告依赖性'com.google.firebase:firebase-ads:18.1.0'中使用

此错误出现在android 9.0设备中

我的代码正在关注

 public static LinearLayout add;
        public static AdView adView;
        public static AdRequest request;

    public void load_add(final LinearLayout addViw) {
            adView = new AdView(Main_open.this);
            adView.setAdSize(AdSize.SMART_BANNER);
            adView.setAdUnitId(BANNAER_ID);
            request = new AdRequest.Builder().build();

            sharedPreference.putInt(getApplicationContext(), "addloded", 0);
            adView.setAdListener(new AdListener() {
                public void onAdLoaded() {
                    sharedPreference.putInt(getApplicationContext(), "addloded", 1);
                    Main_open.load_addFromMain(Main_open.this, add);

                    super.onAdLoaded();
                }

                public void onAdFailedToLoad(int errorcode) {
                    /*load_add(addViw);*/
                }
            });

            adView.loadAd(request);
            if (adView != null) {
                ViewGroup parentViewGroup = (ViewGroup) adView.getParent();
                if (parentViewGroup != null) {
                    parentViewGroup.removeAllViews();
                }
            }
        }

        public static void load_addFromMain(Context context, LinearLayout add_banner) {
            add = add_banner;
            try {
                if (adView != null) {
                    ViewGroup parentViewGroup = (ViewGroup) adView.getParent();
                    if (parentViewGroup != null) {
                        parentViewGroup.removeAllViews();
                    }
                }
                if (sharedPreference.getInt(context, "addloded") == 1) {
                    add_banner.setVisibility(View.VISIBLE);
                    add_banner.removeAllViews();
                    add_banner.addView(adView);
                }

            } catch (Exception e) {
                System.out.println("Ad Exception " + e);
            }

        }
    LinearLayout ads_lay = findViewById(R.id.ads_lay);
    load_addFromMain(CashList_Fragment.this, ads_lay);

1 个答案:

答案 0 :(得分:1)

我不确定,但是将此代码放在应用程序标签下的清单文件中

 <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />