I have a problem:
I've installed an Admob ad banner in my app and when I'm using this command to builder:
builder.addTestDevice(
"0277F42DBB49E3FD56F9EFFE3C4380B4"
)
Everything works (I mean, I see banner with similar text "congrats, bla-bla-bla, etc".
But.
In published game, which of course has disabled this line (addTestDevice) it doesn't show.
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hypeofpipe.westernshooter"
android:versionCode="12"
android:versionName="1.02">
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="25" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/GdxTheme" >
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id"/>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<activity
android:name="com.hypeofpipe.westernshooter.AndroidLauncher"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
AndroidLauncher.java
public class AndroidLauncher extends AndroidApplication
implements UrlOpener, AdHandler {
protected AdView adView;
private final int SHOW_ADS = 1;
private final int HIDE_ADS = 0;
Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
switch (msg.what){
case SHOW_ADS:
adView.setVisibility(View.VISIBLE);
break;
case HIDE_ADS:
adView.setVisibility(View.GONE);
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
adView = new AdView(this);
RelativeLayout layout = new RelativeLayout(this);
View gameView = initializeForView(new MainClass(this, this), config);
adView.setAdListener(new AdListener(){
@Override
public void onAdLoaded() {
int visibility = adView.getVisibility();
adView.setVisibility(AdView.GONE);
adView.setVisibility(visibility);
AudioManager.getInstance().playSound(
AudioManager.getInstance().shot_missed
);
}
});
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(*here goes my unitid from admob*);
AdRequest.Builder builder = new AdRequest.Builder();
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
layout.addView(gameView);
layout.addView(adView, adParams);
adView.loadAd(builder.build());
setContentView(layout);
}
public void openURL(String url) {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
this.startActivity(intent);
}
@Override
public void showAds(boolean show) {
handler.sendEmptyMessage(show ? SHOW_ADS : HIDE_ADS);
}
}
MainClass.java
public class MainClass extends Game {
public static UrlOpener urlOpener;
public static AdHandler adHandler;
public MainClass(UrlOpener urlOpener,
AdHandler adHandler)
{
this.urlOpener = urlOpener;
this.adHandler = adHandler;
adHandler.showAds(false);
}
@Override
public void create() {
Assets.getInstance().load();
Assets.getInstance().assetManager.finishLoading();
setScreen(new ScreenModified(this));
}
}
Some fragment from code, where ads are called to show.
MainClass.adHandler.showAds(true);
Also, I have 0 requests from mine app.