I have a javafx app running on android and would like to place google adwords on some of the screens. The issue I have is that the adwords use googles AdView to display the add which is an Android presentation object and is not compatible with the JavaFX presentation layer.
Sample code that creates AdView
import com.google.android.gms.ads.MobileAds;
import javafxports.android.FXActivity;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
/**
* Constructor creates AdView
* Call getAdView() to retrieve AdView object.
*/
public class GoogleAds {
private AdView adView = null;
public GoogleAds() {
AdView mAdView = createAddView();
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
.build();
mAdView.loadAd(adRequest);
}
...
Now I have a com.google.android.gms.ads.AdView object ready for presentation
I can add it to the android view hierarchy using
private void includeGoogleAdView(LinearLayout layout) {
AdView adView = GoogleAds().getAdView();
layout.addView(mAdView);
}
All this works as expected when run as an android app.
So the question is "can I get an AdView to show in the javafx presentation layer?".
Is there was a way to make an com.google.android.gms.ads.AdView become an instance of javafx.scene.Node then I could add it using something like
private Node addToPane(AdView adView) {
javafx.scene.layout.Pane pane = new javafx.scene.layout.Pane();
pane.getChildren().addAll( canvas, adView);
return pane;
}
Or is there another solution?