Hello,
I’m new here, I’m testing this wonderful engine and I would like to ask if is any solution to integrate AdMob ads if anyone has any small example would be great. My application extends from SimpleApplication.
Thanks
For desktop or for android?
And what are admob? a html part you should integegrate? a link? a image? flash?
- For android apps.
AdMob is an ad network from Google. Here is small guide about admob banner for Android (and other): https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals
So, admob is a custom android view that must be on top of the glsurfaceview.
- Can you tell me where to find information and how to add html, flash in desktop application?
Thanks
1 no idea I dont do anything for android
2 probably the best current way is the jfx integration for html and javascript, flash wont work. JFX might only be available on desktop for quite some time.
A possible alternative to JavaFX (I’m not saying it’s better) is Chromiumembedded. As opposed to JFX there’s no jME3 integration for it already in place though.
Yes, there is a pretty easy way to integrate addmob. I already did it.
First you need to do everything as you would for a classic Android app (integrate the jar, and declare the ad activity in the manifest)
You need to override the layoutDisplay method of the JME’s Android MainActivity
Here is what I did
private AdView adView;
public void layoutDisplay() {
initAdView();
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT,
Gravity.CENTER);
frameLayout = new FrameLayout(this);
splashImageView = new ImageView(this);
if (splashPicID != 0) {
Drawable drawable = this.getResources().getDrawable(splashPicID);
if (drawable instanceof NinePatchDrawable) {
splashImageView.setBackgroundDrawable(drawable);
} else {
splashImageView.setImageResource(splashPicID);
}
}
frameLayout.addView(view);
if (splashPicID != 0) {
frameLayout.addView(splashImageView, lp);
}
setContentView(frameLayout);
logger.log(Level.INFO, "Splash Screen Created");
}
private void initAdView() {
// Create the adView
adView = new AdView(this, AdSize.BANNER, "INSERT_YOUR_AD_UNIT_ID_HERE");//I don't remember how you get an ad unit, but you'll find that on google.
}
public void showAdView(final boolean visible) {
//System.out.println("Ad view requested " + visible);
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="@+id/mainLayout"
this.runOnUiThread(new Runnable() {
@Override
public void run() {
if (visible) {
// Add the adView to it
frameLayout.addView(adView);
AdRequest request = new AdRequest();
// Initiate a generic request to load it with an ad
request.addTestDevice("A4FB1D57A3DF433A20FAB5C7846E5C79");//remember to do this (with your device hash) to avoid having your test device banned from ad mob.
adView.loadAd(request);
} else {
frameLayout.removeView(adView);
}
}
});
}
@Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
///.....
}
I used this code for a game called stack3d (demo only), the ads are displayed when you’re in the menu that’s why I have a method to show and hide the view
@nehon said: Yes, there is a pretty easy way to integrate addmob. I already did it. First you need to do everything as you would for a classic Android app (integrate the jar, and declare the ad activity in the manifest)You need to override the layoutDisplay method of the JME’s Android MainActivity
Here is what I did
Thanks, for [java]code[/java] , but how can i showAdView from mygame.Main how to call method for showing adview?
I tried to use textview instead adView, but nothing shown.