Clone wiki

love-android-sdl2 / AdMob Instructions

Note: This is a unsupported and very rough guide.

Make sure you have read and understand https://developers.google.com/mobile-ads-sdk/ first!

The changes you have to make include:

  • changing GameActivity.java
  • add google-play-services_lib to android project

Here are the changes outlined you need to do in the GameActivity.java.

import com.google.android.gms.ads.*;

public class GameActivity extends SDLActivity {

    ...

    private AdView adView;

    @Override protected void onCreate(Bundle savedInstanceState) {
        ...

        super.onCreate(savedInstanceState);
        getWindowManager().getDefaultDisplay().getMetrics(metrics);

        adView = new AdView(mSingleton);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId("APPLICATION_BANNER_ID");

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        params.addRule(RelativeLayout.CENTER_HORIZONTAL);

        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);
        mLayout.addView(adView, params);
    }
}

Updated