java - Unable to show interstitial ads with admob in andengine -
i have been trying show interstitials in andengine developed game unable to. have integrated banner ads though. prefer using coding layout. below gameactivity.java , gamescene.java classes, please in understanding root error?
public class gameactivity extends basegameactivity { private smoothcamera camera; public music music;` public static int flag=0; @override public engine oncreateengine(engineoptions pengineoptions) { return new limitedfpsengine(pengineoptions, 60); } public engineoptions oncreateengineoptions() { camera = new smoothcamera(0, 0, 720, 1280,5000000,5000000,1); engineoptions engineoptions = new engineoptions(true, screenorientation.portrait_fixed, new fillresolutionpolicy(), this.camera); engineoptions.getaudiooptions().setneedsmusic(true).setneedssound(true); engineoptions.getrenderoptions().getconfigchooseroptions().setrequestedmultisampling(true); engineoptions.setwakelockoptions(wakelockoptions.screen_on); engineoptions.gettouchoptions().setneedsmultitouch(true); return engineoptions; } @override public boolean onkeydown(int keycode, keyevent event) { if (keycode == keyevent.keycode_back) { scenemanager.getinstance().getcurrentscene().onbackkeypressed(); } return false; } public void oncreateresources(oncreateresourcescallback poncreateresourcescallback) throws ioexception { resourcesmanager.preparemanager(mengine, this, camera, getvertexbufferobjectmanager()); poncreateresourcescallback.oncreateresourcesfinished(); try { music = musicfactory.createmusicfromasset(mengine.getmusicmanager(), this,"music/music.ogg"); } catch (ioexception e) { e.printstacktrace(); } } adview adview ;@override @suppresslint("newapi") protected void onsetcontentview() { final framelayout framelayout = new framelayout(this); final framelayout.layoutparams framelayoutlayoutparams = new framelayout.layoutparams( framelayout.layoutparams.match_parent, framelayout.layoutparams.match_parent, gravity.fill); final framelayout.layoutparams adviewlayoutparams = new framelayout.layoutparams(framelayout.layoutparams.wrap_content, framelayout.layoutparams.wrap_content, gravity.center | gravity.top); adview = new adview(this); adview.setadunitid("admobid"); //adview.setadunitid("admobid"); adview.setadsize(adsize.); adview.setvisibility(adview.visible); adview.refreshdrawablestate(); adrequest adrequest = new adrequest.builder().build(); adview.loadad(adrequest); if (android.os.build.version.sdk_int > android.os.build.version_codes.gingerbread_mr1) { adview.setlayertype(view.layer_type_software, null); } this.mrendersurfaceview = new rendersurfaceview(this); mrendersurfaceview.setrenderer(mengine, this); final framelayout.layoutparams surfaceviewlayoutparams = new framelayout.layoutparams( android.view.viewgroup.layoutparams.match_parent, android.view.viewgroup.layoutparams.match_parent); surfaceviewlayoutparams.gravity = gravity.center; framelayout.addview(this.mrendersurfaceview, surfaceviewlayoutparams); adview.setadlistener(new adlistener() { public void onadloaded(){ if(flag==0) {flag=1; framelayout.addview(adview, adviewlayoutparams); } } }); this.setcontentview(framelayout, framelayoutlayoutparams); } public void oncreatescene(oncreatescenecallback poncreatescenecallback) throws ioexception { scenemanager.getinstance().createsplashscene(poncreatescenecallback); } public void onpopulatescene(scene pscene, onpopulatescenecallback ponpopulatescenecallback) throws ioexception { mengine.registerupdatehandler(new timerhandler(2f, new itimercallback() { public void ontimepassed(final timerhandler ptimerhandler) { mengine.unregisterupdatehandler(ptimerhandler); scenemanager.getinstance().createmenuscene(); } })); ponpopulatescenecallback.onpopulatescenefinished(); } @override protected void onpause() { scenemanager.getinstance().gamescene.onbackkeypressed(); super.onpause(); } @override protected void ondestroy() { super.ondestroy(); system.exit(0); } }
gameover method trying put interstitial
private void gameover() {this.gameovercheck = 1; this.setignoreupdate(true); sprite gameover = new sprite(camera.getcenterx(), camera.getcentery(), resourcesmanager.gameover, vbom); this.attachchild(gameover); rocket.setcurrenttileindex(2); activity.runonuithread(new runnable(){ @override public void run() { // todo auto-generated method stub interstitialad interstitial = new interstitialad(activity); interstitial.setadunitid("ca-app-pub-3940256099942544/1033173712"); adrequest adrequest = new adrequest.builder().build(); interstitial.loadad(adrequest); interstitial.show(); } }); soundonbtn1 = new sprite(camera.getcenterx(),camera.getcentery()-200, resourcesmanager.retry, vbom) { public boolean onareatouched(touchevent pscenetouchevent, float x, float y) {if(pscenetouchevent.isactiondown()) scenemanager.getinstance().loadgamescene1(engine); gameovercheck=0; editor.commit(); editor.commit(); return true; }; }; this.attachchild(soundonbtn1); this.registertoucharea(soundonbtn1);
you have make sure interstitial ad preloaded, otherwise won't shown.
preload interstitial.loadad(adrequest);
e.g. when start scene.
and in gameover method check isloaded this
boolean loaded = interstitialad.isloaded(); if (loaded) { interstitial.show(); } else { //loadyourinterstitial }
Comments
Post a Comment