Search code examples
androidlibgdxadsappodeal

Appodeal Banner Ad Covers Screen Android/LibGDX


I’m trying to insert Appodeal banner adds into a LibGDX application but the banner ad is covering the screen instead of being placed above it. I cannot find any tutorials for using Appodeal in LibGDX, so I’m working from this tutorial on using Admob in LibGDX. https://github.com/libgdx/libgdx/wiki/Admob-in-libgdx

I cannot figure out how to get the Appodeal banner ad in the form of a View which can be added to the RelativeLayout using the addView() method. I have tried a couple ways to do this which are labeled “ATTEMPT #1” and “ATTEMPT #2” but in both attempts the banner ad does not display at all. The line “Appodeal.show(this, BANNER);” places the banner on top of the screen, so that is commented out. Any help getting this figure out would be greatly appreciated. Thanks.

Here is my AndroidLauncher.java file where I create and show the banner ad.

public class AndroidLauncher extends AndroidApplication {
    private final int BANNER = 4;

    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();

        // LAYOUT: combines LibGDX View and Ad View
        RelativeLayout relativeLayout = new RelativeLayout(this);

        // Ad View
        Appodeal.initialize(this, "fee50c333ff3825fd6ad6d38cff78154de3025546d47a84f", BANNER);
        Appodeal.setTesting(true);
//        Appodeal.show(this, BANNER);
        // ATTEMPT #1
        BannerView bannerView = Appodeal.getBannerView(this);
        // ATTEMPT #2
//        BannerView bannerView = new BannerView(this, null);
//        Appodeal.setBannerViewId(bannerView.getId());

        // LibGDX View
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);     
        View libgdxView = initializeForView(new AppodealGDXDemo(), config);

        // add to view
        relativeLayout.addView(bannerView);
        relativeLayout.addView(libgdxView);

        // set layout
        setContentView(relativeLayout);
    }
}

Solution

  • I finally found info on the Appodeal website that helped me out. https://wiki.appodeal.com/en/android/2-5-8-android-sdk-integration-guide/ad-types It appears they have made a lot of changes to their website as the links to documentation on their website that I found from google redirected to the main page.

    I got it working now and here is the updated code.

    public class AndroidLauncher extends AndroidApplication {
        @Override
        protected void onCreate (Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
    
            // LAYOUT: combines LibGDX View and Ad View
            LinearLayout layout = new LinearLayout(this);
            layout.setOrientation(LinearLayout.VERTICAL);
    
            // Ad View
            Appodeal.initialize(this, "fee50c333ff3825fd6ad6d38cff78154de3025546d47a84f", Appodeal.BANNER_VIEW);
            Appodeal.setTesting(true);
            BannerView bannerView = Appodeal.getBannerView(this);
            Appodeal.show(this, Appodeal.BANNER_VIEW);
    
            // LibGDX View
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);     
            View libgdxView = initializeForView(new AppodealGDXDemo(), config);
    
            // add to layout
            layout.addView(bannerView);
            layout.addView(libgdxView);
    
            // set layout
            setContentView(layout);
        }
    }