How to implement the AdMob in the libgdx project on Android Studio
-
Anyway, I've got:
Project-level build.gradle classpath 'com.google.gms:google-services:3.0.0' ependencies { ... compile 'com.google.firebase:firebase-core:9.2.0' compile 'com.google.firebase:firebase-ads:9.2.0' } ...
apply plugin: 'com.google.gms.google-services'
In string.xml wrote
<string name="banner_ad_unit_id">ca-app-pub-xxxxxxxxxxx</string>
What do we do next? In libgdx, you need to create activity_main.xml?
And then in the middle of the class, do you have the next code?MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544~3347511713");
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);?
-
The AndroidLauncher section needs to be amended to add a display container:
public class AndroidLauncher extends AndroidApplication { @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); RelativeLayout main_layout = new RelativeLayout(this); View gameView = initializeForView(new MainClass(), config); main_layout.addView(gameView);
/**Тут непосредственно формируем место для банера*/ RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); adParams.addRule(RelativeLayout.CENTER_HORIZONTAL); main_layout.addView(banner, adParams); /***/ setContentView(main_layout); AdRequest adRequest = new AdRequest.Builder().addTestDevice("идентификатор_тестового_устройства").build(); banner.loadAd(adRequest); } }
Further details http://olelucoye.ru/publ/libgdx/libgdx_i_admob/7-1-0-86
You need to use a handler to activate/deactivation.