bool onTop = true;
bool show = true;
if (show) {
env->CallStaticVoidMethod(localcls, showAds, ontop);
} else {
env->CallStaticVoidMethod(localcls, hideAds);
}
env->DeleteGlobalRef(localcls);
in your java activity class:
public static void showAds(final boolean ontop) {
[…]
}
public static void hideAds() {
[…]
}
These are just stripped down lines from my code - so i’m sure it
compiles - but you should see how it works, you should of course cache
the localcls, the env and the methodidsAm 11.10.2013 14:20, schrieb glezmen:
Thank you for your help!
I modified my code according to your code snippets, and now it compiles, and I can see the grey rectangle at the bottom of the screen (i waited for something like 10 minutes), and nothing else, the main screen of my app is not displayed.
In other tutorials/example codes I see jvm->AttachCurrentThread() calls, isn’t is neccessary?
// Our popup window, you will call it from your C/C++ code later
public static void showAdPopup()
{
//if(adsinited)
//{
// return;
//}
if(adView!=null) {
_activity.runOnUiThread(new Runnable() {
@Override
public void run() {
adsinited = true;
// Out popup window
popUp = new PopupWindow(_activity);
// This is the minimum size for AdMob, we need to set this in case our target device run at 320x480 resolution (Otherwise no ad will be shown, see the padding kill below)
popUp.setWidth(320);
popUp.setHeight(50);
popUp.setWindowLayoutMode(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
popUp.setClippingEnabled(false);
layout = new LinearLayout(_activity);
mainLayout = new LinearLayout(_activity);
// The layout system for the PopupWindow will kill some pixels due to margins/paddings etc
(No way to remove it), so padd it to adjust
layout.setPadding(-5, -5, -5, -5);
MarginLayoutParams params = new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, 0);
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(adView, params);
popUp.setContentView(layout);
_activity.setContentView(mainLayout, params);
AdRequest adRequest = new AdRequest();
// Enable this if your are testing AdMob, otherwise you’ll risk to be banned!
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
_activity.adView.loadAd(adRequest);
// Show our popup window
popUp.showAtLocation(mainLayout, Gravity.BOTTOM, 0, 0);
popUp.update();
}});
}
}
Now i tried to call the showAdPopup() right before starting my Main Menu loop, and the only thing I get is a black screen with a small gray rectangle at the bottom
Ladies and gentlemen, I can announce a success
I couldn’t manage AdMob work (I’m pretty sure something is wrong on the Java side), but I tried Chartboost interstitial ads, and it works perfectly, using (almost) the same code pasted above (and adding example from the Chartboost help page).
Thanks for the help, Martin!