PlayN with AdMob ?

214 views
Skip to first unread message

milord.me

unread,
Feb 10, 2012, 9:04:19 PM2/10/12
to pl...@googlegroups.com

Hi,

Anyone has experience / pointer on how to integrate Admob/Adwhirl into an PlayN game?

Best.

Avi Yafe

unread,
Mar 17, 2013, 1:47:01 AM3/17/13
to pl...@googlegroups.com
Hi,
did you figure it out?

thanks, Avi

Neil White

unread,
Mar 17, 2013, 7:13:25 AM3/17/13
to pl...@googlegroups.com
i havnt set it up yet but you will need to write android specific code for full control and/or  use layouts files

when i last checked for using platform specific code documentation was lacking and i am stupid does anyone have a working example 

Bryan Alvarado

unread,
Mar 17, 2013, 12:01:30 PM3/17/13
to pl...@googlegroups.com
We managed to made it work, here is how we did it.


If anyone feels it should be located in the wiki and wants to clean it up to  put it in there, I think Michael wouldn't mind to help with that.


2013/3/17 Neil White <clear...@gmail.com>
i havnt set it up yet but you will need to write android specific code for full control and/or  use layouts files

when i last checked for using platform specific code documentation was lacking and i am stupid does anyone have a working example 

--
 
---
You received this message because you are subscribed to the Google Groups "PlayN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to playn+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Bryan Alvarado
502 Studios
http://about.me/bryan.

Tim O'Brien

unread,
Mar 5, 2014, 9:59:13 AM3/5/14
to pl...@googlegroups.com, br...@502studios.net
Hi Bryan,

What version of PlayN are you using?  I'm having problems with the onCreate method and setting up the layouts, AndroidLayoutView undefined and my GameViewGL constructor wants (context, AndroidPlatform, AndroidGL20).

Also, have you tried using the InterstitialAd with any success?

Tim

Bryan Alvarado

unread,
Mar 5, 2014, 11:58:11 AM3/5/14
to Tim O'Brien, pl...@googlegroups.com
I just updated the gist to reflect the changes made when we moved to 1.7.2, the whole onCreate thing was removed and was much nicer to integrate, but we never tried InterstitialAd though.

Here is the link to the new gist. I hope it helps!
Bryan Alvarado
502 Studios

Tim O'Brien

unread,
Mar 5, 2014, 12:08:42 PM3/5/14
to pl...@googlegroups.com, Tim O'Brien, br...@502studios.net
Thanks Bryan,  

I'm moving to PlayN 1.8.5 and using Google Play Services rev 15 with (Games, Plus and Admod). I have the Games and Plus API integration done but the Admod stuff is driving me nuts.  I see the request logged in the Admod console but nothing on screen.

I will let you know how I make out.

Tim

Tim O'Brien

unread,
Mar 7, 2014, 8:54:50 AM3/7/14
to pl...@googlegroups.com, Tim O'Brien, br...@502studios.net
Hi Bryan,

Thank you so much for the updated code!!!! I have the com.google.android.gms.ads.AdView showing now along with Google Play Game API :D

Initially I was missing the AdView.pause() & AdView.resume() methods in my onResume() & onPause overrides and it caused the following exception when the game resumed.  However, its all good now.

03-06 19:43:25.868 E/AndroidRuntime( 4830): java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
03-06 19:43:25.868 E/AndroidRuntime( 4830): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
03-06 19:43:25.868 E/AndroidRuntime( 4830): at java.util.ArrayList.get(ArrayList.java:304)
03-06 19:43:25.868 E/AndroidRuntime( 4830): at playn.core.gl.GroupLayerGL.render(GroupLayerGL.java:183)
03-06 19:43:25.868 E/AndroidRuntime( 4830): at playn.core.gl.GroupLayerGL.paint(GroupLayerGL.java:176)
03-06 19:43:25.868 E/AndroidRuntime( 4830): at playn.core.gl.GL20Context.paint(GL20Context.java:71)
03-06 19:43:25.868 E/AndroidRuntime( 4830): at playn.android.AndroidGraphics.paint(AndroidGraphics.java:230)
03-06 19:43:25.868 E/AndroidRuntime( 4830): at playn.android.GameViewGL$1.onDrawFrame(GameViewGL.java:62)
03-06 19:43:25.868 E/AndroidRuntime( 4830): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
03-06 19:43:25.868 E/AndroidRuntime( 4830): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

Tim

Tim O'Brien

unread,
Mar 21, 2014, 10:24:23 AM3/21/14
to pl...@googlegroups.com, Tim O'Brien, br...@502studios.net
Hi Bryan,

I'm getting a weird issue with pause & resume of the game only when using the RelativeLayout and not when the contentview is the GameViewGL.  Initially I load up the RelativeLayout as you have in your code and on game start I show the banner ad, everything look fine at this point. When I hit the Home button and then go back, I see game view for a split second and then the entire screen goes black. I'm not sure if I should be doing something with the gameview onresume?? Latest version of Admob in Google Play Services requires AdView.pause() & AdView.resume().

public void ShowBannerAd() {
if (!doAdvertising) return;
runOnUiThread(new Runnable(){
@Override
public void run() {
if (adView!=null) {
adView.bringToFront();
adView.setVisibility(View.VISIBLE);
adView.startLayoutAnimation();
}
}
});
}

Tim O'Brien

unread,
Mar 21, 2014, 1:03:22 PM3/21/14
to pl...@googlegroups.com, Tim O'Brien, br...@502studios.net
This might also be of help.  I'm still getting the following error, even with Admob.pause() & Admob.resume(), but its not consistent.

03-21 14:29:41.420 E/OpenGLRenderer(19531):   GL_INVALID_OPERATION
03-21 14:29:41.425 E/AndroidRuntime(19531): FATAL EXCEPTION: GLThread 63824
03-21 14:29:41.425 E/AndroidRuntime(19531): java.lang.IndexOutOfBoundsException: Invalid index 5, size is 5
03-21 14:29:41.425 E/AndroidRuntime(19531): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
03-21 14:29:41.425 E/AndroidRuntime(19531): at java.util.ArrayList.get(ArrayList.java:304)
03-21 14:29:41.425 E/AndroidRuntime(19531): at playn.core.gl.GroupLayerGL.render(GroupLayerGL.java:183)
03-21 14:29:41.425 E/AndroidRuntime(19531): at playn.core.gl.GroupLayerGL.paint(GroupLayerGL.java:176)
03-21 14:29:41.425 E/AndroidRuntime(19531): at playn.core.gl.GL20Context.paint(GL20Context.java:71)
03-21 14:29:41.425 E/AndroidRuntime(19531): at playn.android.AndroidGraphics.paint(AndroidGraphics.java:230)
03-21 14:29:41.425 E/AndroidRuntime(19531): at playn.android.GameViewGL$1.onDrawFrame(GameViewGL.java:62)
03-21 14:29:41.425 E/AndroidRuntime(19531): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
03-21 14:29:41.425 E/AndroidRuntime(19531): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

Tim O'Brien

unread,
Mar 22, 2014, 10:55:42 AM3/22/14
to pl...@googlegroups.com
I have isolated the issue to the Admob bringtofront call. If I call it more then once or after a resume the screen goes black. If I run gameview bringtofront its good but can no longer see the adview.

Tim O'Brien

unread,
Mar 25, 2014, 7:48:54 AM3/25/14
to pl...@googlegroups.com
Ok, I finally figured it out after playing around with layouts and switching from Admob in Game Play Service to Admob 6.4.  

The problem was in my game's init method, for some reason that I can't remember now I had added the following LifecycleListener. I think it was because my screen would black out on resume. Anyways, that is not the case with newer versions of PlayN, I commented out this code and with the code that Bryan Alvarado supplied, everything works just great. I'm now using Game Play Service (Games API, Plus API, & Ads) v15 with PlayN 1.8.5.

//    PlayN.setLifecycleListener(new LifecycleListener(){
// @Override
// public void onPause() {
// if (graphics().ctx().quadShader(null) != null) {
// graphics().ctx().quadShader(null).clearProgram();
// }
// if (graphics().ctx().trisShader(null) != null) {
// graphics().ctx().trisShader(null).clearProgram();
// }
// }
// @Override
// public void onResume() {
//
// }
// @Override
// public void onExit() {
// if (graphics().ctx().quadShader(null) != null) {
// graphics().ctx().quadShader(null).clearProgram();
// }
// if (graphics().ctx().trisShader(null) != null) {
// graphics().ctx().trisShader(null).clearProgram();
// }
// }
// });

Bryan Alvarado

unread,
Mar 25, 2014, 7:29:01 PM3/25/14
to pl...@googlegroups.com
I'm very sorry that I couldn't help you out more the last few days, have been kind of busy days. But I'm glad that you got it working!


--

---
You received this message because you are subscribed to the Google Groups "PlayN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to playn+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim O'Brien

unread,
Mar 26, 2014, 12:04:31 PM3/26/14
to pl...@googlegroups.com, br...@502studios.net
Hi Bryan,

That's ok, hopefully the conversation with myself will help someone else (future me) if they run into the same issue.

Tim

Mike Twohey

unread,
Jun 19, 2014, 7:43:47 PM6/19/14
to pl...@googlegroups.com, br...@502studios.net
Thank you for helping us setup our Admob API!  Now we went with the older version 6.4.1 which becomes unsupported in Aug 2014.   Have you been able to port this sample code to the new version of Admob?

Tim O'Brien

unread,
Jun 20, 2014, 7:33:10 AM6/20/14
to pl...@googlegroups.com, br...@502studios.net
Hi Mike,

I'm currently using the new Admod. which is part of Google Play Services. I'm using Google Games, Plus, & Ads APIs, below is a link to another post I did on Google Play Services integration.

 
My Android class didn't change much from 6.4 except for the imports. 
     import com.google.android.gms.ads.AdListener;
     import com.google.android.gms.ads.AdRequest;
     import com.google.android.gms.ads.AdSize;
     import com.google.android.gms.ads.AdView;


While Ads are included in Google Play Services library, Google Play Services is not require to be on the device to use Ads.  Other APIs such as Games requires the service to be installed so you should check to see if its installed before using those APIs.  This way you can have one APK that shows ads on all devices and will take advantage of Google Play Games if installed. Below is code related to use Play Games API and is not required for Ads, just in case you were interested.

                        //Setup Google Play Services for use in PlayN if installed
googlePlayStatus = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (googlePlayStatus != ConnectionResult.SUCCESS) return;
//Create Google Helper taken from Google sample code
if (mGoogle==null) mGoogle = new GameHelper(this, mRequestedClients); //Request APIs like Games, Plus. Ads don't be requested.

//Social Service is your class that implements an interface you define in your core project to allow game to access
SocialService s = new SocialService(mGoogle); //Create you class with the Google Game Helper class
mGoogle.setup((GameHelperListener)s);  //Your Social Service will also implement the Game Helper interface
game.setSocial(social); //If your game your interface to your social class


Tim
Reply all
Reply to author
Forward
0 new messages