I am using andengine for my game development with google play services, my game works fine. But once I added admob with "onSetContentView" callback called, my game screen goes black and only ads are visible. Here is my callback onSetContentView function:
@override
protected void onSetContentView() {
this.mRenderSurfaceView = new RenderSurfaceView(this);
this.mRenderSurfaceView.setRenderer(mEngine, this);
final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams = new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());
Log.i(TAG,"In funcion OnSetContaitView");
//Creating the banner view.
AdView adView = new AdView(this);
adView.setAdSize(com.google.android.gms.ads.AdSize.BANNER);
adView.setAdUnitId("my adunit id");
//create add req
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)// This is for emulators
//test mode on DEVICE (this example code must be replaced with your device uniquq ID)
.addTestDevice("2EAB96D84FE62876379A9C030AA6A0AC") // Nexus 5
.addTestDevice("TA93303NP9")
.build();
adView.loadAd(adRequest);
final FrameLayout.LayoutParams adViewLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
final FrameLayout frameLayout = new FrameLayout(this);
final FrameLayout.LayoutParams frameLayoutLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT);
frameLayout.addView(this.mRenderSurfaceView,surfaceViewLayoutParams);
frameLayout.addView(adView,adViewLayoutParams);
this.setContentView(frameLayout, frameLayoutLayoutParams);
adView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
Currently I am able to see either game screen or ads. Please suggest how to get game screen along with ads.
Thanks in Advance.