I've recently started learning Java for android development. My first game is almost ready to publish in Google Play, but I'm affraid that google might say that on the one screen, the ad may be clicked accidentally, So I would like to hide it on that screen. The thing is, that Adview is initiated only in AndroidLuncher class in android project, but all the other classes are in core project. So what I'm asking for is a way to instruct Admob to hide when player enters GameScreen. Is that possible?
I could provide some code, but I don't know which part could help you, so I'll just post the AndroidLauncher Class onCreate method:
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useAccelerometer = false;
config.useCompass = false;
RelativeLayout layout = new RelativeLayout(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// Create the libgdx View
View gameView = initializeForView(new MainClass(), config);
AdView AdView = new AdView(this);
AdView.setAdSize(AdSize.SMART_BANNER);
AdView.setAdUnitId("ca-app-pub-SECRETCODE/HERE"); //The AdUnitId
if(isNetworkAvailable())
{
AdView.setBackgroundColor(Color.BLACK);
}
AdRequest.Builder adRequest = new AdRequest.Builder();
adRequest.addTestDevice("HERE_TOO"); //Test device
AdView.loadAd(adRequest.build());
layout.addView(gameView);
// Add the AdMob view
RelativeLayout.LayoutParams adParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layout.addView(AdView, adParams);
// Hook it all up
setContentView(layout);
AdView.setVisibility(View.VISIBLE);
}
This code works just fine, so I would prefer not to change it, as I've spent many hours getting it to work :)