How to integrate banner ads of unity to flutter

1,162

We have the same issue. You can follow our evolution of the plugin here: FlutterUnityAds.

We also asked to the Reddit Flutter Community if someone can help us: Reddit discussion

Hope we'll get some answers. Please, tell us if you find how to solve that problem.

Share:
1,162
game game
Author by

game game

Updated on December 12, 2022

Comments

  • game game
    game game 11 months

    I am trying to add banner ads to unity_ads_flutter plugin. But where can I add banner view to activity? Can anyone provide me some ideas and examples? The hard part is that I don't know how to integrate code in onUnityBannerLoaded(in the example) to flutter plugin.

    This is a link to unity_ads_flutter plugin: https://github.com/EPNW/unity_ads_flutter This is a link to unity guide: https://unityads.unity3d.com/help/android/integration-guide-android#banner-ads

    Example Code from unity guide:

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

    To be more clear, I want to ask how to add the view returned from onUnityBannerLoaded

    • game game
      game game over 4 years
      To be more clear, I want to ask how to add the view returned from onUnityBannerLoaded.
    • Robert Williams
      Robert Williams almost 4 years
      did you find any solution? I am trying to monetize my flutter app. I dont want to use admob can you suggest me what should i do?
  • Robert Williams
    Robert Williams almost 4 years
    did u find any solution?