如何将统一的横幅广告整合起来

时间:2019-06-22 07:29:34

标签: java android unity3d flutter

我正在尝试将横幅广告添加到unity_ads_flutter插件。但是我可以在哪里向活动添加横幅视图?谁能给我一些想法和例子?困难的部分是我不知道如何将onUnityBannerLoaded(在示例中)中的代码集成到Flutter插件中。

这是unity_ads_flutter插件的链接:https://github.com/EPNW/unity_ads_flutter 这是团结指南的链接:https://unityads.unity3d.com/help/android/integration-guide-android#banner-ads

统一指南中的示例代码:

    public class UnityBannerExample extends Activity {
        private String unityGameId = “1234567”;
        private Bool testMode = true;
        private String placementId = “banner”;
        private View bannerView;

        @Override
        protected void onCreate (Bundle savedInstanceState) {
            super.onCreate (savedInstanceState);
            setContentView (R.layout.unityads_example_layout);
            final Activity myActivity = this;
            // Declare a new banner listener, and set it as the active banner listener:
            final IUnityBannerListener myBannerListener = new UnityBannerListener ();
            UnityBanners.setBannerListener (myBannerListener);
            // Initialize the Ads SDK:
            UnityAds.initialize (this, unityGameID, myAdsListener, testMode);
        }

        // Implement a function to display or destroy a banner ad: 
        @Override
        public void ToggleBannerAd () {
            // If no banner exists, show one; otherwise remove the existing one:
            if (bannerView == null) {
                // Optionally specify the banner’s anchor position:
                UnityBanners.setBannerPosition (BannerPosition.BOTTOM_CENTER);
                // Request ad content for your Placement, and load the banner:
                UnityBanners.loadBanner (myActivity, "banner");
            } else {
                UnityBanners.destroy ();
            }
        }

        // Implement the banner listener interface methods:
        private class UnityBannerListener implements IUnityBannerListener {

            @Override
            public void onUnityBannerLoaded (String placementId, View view) {
                // When the banner content loads, add it to the view hierarchy:
                bannerView = view;
                ((ViewGroup) findViewById (R.id.unityads_example_layout_root)).addView (view);
            }

            @Override
            public void onUnityBannerUnloaded (String placementId) {
                // When the banner’s no longer in use, remove it from the view hierarchy:
                bannerView = null;
            }

            @Override
            public void onUnityBannerShow (String placementId) {
                // Called when the banner is first visible to the user.
            }

            @Override
            public void onUnityBannerClick (String placementId) {
                // Called when the banner is clicked.
            }

            @Override
            public void onUnityBannerHide (String placementId) {
                // Called when the banner is hidden from the user.
            }

            @Override
            public void onUnityBannerError (String message) {
                // Called when an error occurred, and the banner failed to load or show. 
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

我们有同样的问题。您可以在此处关注我们插件的演变: FlutterUnityAds

我们还询问了Reddit Flutter社区是否有人可以帮助我们:Reddit discussion

希望我们会得到一些答案。请告诉我们您是否找到解决该问题的方法。