Skip to content

Conversation

pabulaner
Copy link

The ads module provides mobile developers (at the moment only android) with the ability to show banner, interstitial and rewarded ads from JavaFX.

It uses the Google AdMob SDK for loading and showing ads.

@pabulaner
Copy link
Author

INFO: For merging this pull request, an entry would have to be added to the gluonfx-maven-plugin.

@pabulaner
Copy link
Author

Hey, it would be nice to maybe get some feedback or comment on this pull request after one year, because I put a lot of effort into this one and would really like to see it integrated in gluon attach itself.

@jperedadnr
Copy link
Contributor

jperedadnr commented Apr 22, 2025

Thanks @pabulaner for this PR

Could you please sync your branch with head? We use Android SDK 34 now, and it would be good to update the ADS dependency probably to the latest one.

Also, note that all files should have a license header.

And for testing this PR it would be great if you provide a small code snippet of how it can be used.

I've managed to build the service and deploy it to Android with this:

AdsService.create().ifPresent(ads -> {
                            ads.initialize(() -> {
                                ads.setRequestConfiguration(new RequestConfiguration.Builder()
                                        .setTestDeviceIds(List.of(AdsService.BANNER_TEST_AD_UNIT_ID))
                                        .build());
                                ads.newBannerAd();
                            });
                        });

but the initialize call doesn't seem to succeed. All I see in the logs is:

 I/GluonAttach(  910): JNI_OnLoad_ads called
 D/GluonAttach(  910): [Ads Service] Initializing native Ads from OnLoad 
 D/GraalCompiled(  910): Apr 22, 2025 12:25:11 PM com.gluonhq.attach.ads.AdRegistry <init>
 D/GraalCompiled(  910): INFO: AdRegistry(): {id=0, handlers={OnUserEarnedRewardListener=com.gluonhq.attach.ads.OnUserEarnedRewardListener$Handler@6c0109b6, FullScreenContentCallback=com.gluonhq.attach.ads.FullScreenContentCallback$Handler@1ac5ffc5, InterstitialAdLoadCallback=com.gluonhq.attach.ads.AdLoadCallback$Handler@2c9db309, RewardedAdLoadCallback=com.gluonhq.attach.ads.AdLoadCallback$Handler@30ed74db, AdListener=com.gluonhq.attach.ads.AdListener$Handler@7136a281}, ads={}, callbacks:{}}
 V/GluonAttach(  910): Initializing MobileAds...

@pabulaner
Copy link
Author

Thanks for the feedback.
I will look into it this or next week.

@pabulaner
Copy link
Author

I implemented the feedback and here is a short example that should work:

AdsService.create().ifPresent(service -> {
            service.initialize(() -> {
                BannerAd ad = service.newBannerAd();
                
                ad.setAdUnitId(AdsService.BANNER_TEST_AD_UNIT_ID);
                ad.setLayout(BannerAd.Layout.BOTTOM);
                ad.setAdSize(BannerAd.Size.BANNER);
                ad.setAdListener(new AdListener() {
                    // add some listeners like onAdClicked, onAdClosed(), ...
                });
                
                // currently no settings in AdRequest are supported
                ad.load(new AdRequest.Builder().build());
                
                // now the banner ad should appear
            });
        });

I did not test this myself yet, as I don't have the time right now.
I will probably get to it at the end of next month.

PS: Sorry for the long delay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants