Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [LibGDX] Integrating RevMob  (Read 3722 times)
0 Members and 1 Guest are viewing this topic.
Offline CTucker1327
« Posted 2014-05-22 21:42:29 »

So, It took me awhile to get this working... and after I finally got it working.... I realized RevMob isn't what I wanted. Lol. :facedesk:

Anyway, let's get started.

In your core project, create a new package. "com.companyname.gamename.monetization"

Create a new interface called RevmobAdInterface. (Created the same way as a class)
Make sure that class looks like this.
1  
2  
3  
4  
5  
6  
package com.companyname.gamename.monetization;

public interface RevmobAdInterface {
    public void showInterstitialAds(boolean show);
    public void showBannerAd(boolean show);
}



Once completed, head over to your android project.
Create a new package -- Once again called com.companyname.gamename.android.monetization
Make that class name "RevMobIntegration" and look like this

Note: You'll have to replace all of your imports with the proper thing, (IE Replace com.fmeg.tapout with com.company.game)
Note: This class assumes your main android class is AndroidLauncher.java. Your main class will extends AndroidApplication.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
package com.fmeg.tapout.android.monetization;

import android.util.Log;

import com.fmeg.tapout.android.AndroidLauncher;
import com.fmeg.tapout.monetization.RevmobAdInterface;
import com.revmob.RevMob;
import com.revmob.RevMobAdsListener;
import com.revmob.RevMobTestingMode;
import com.revmob.ads.banner.RevMobBanner;
import com.revmob.ads.fullscreen.RevMobFullscreen;

public class RevMobIntegration implements RevmobAdInterface {
   
   private static final String APPLICATION_ID = "YourAdmobAppIDHere";
   
        // Set this to false when creating the version for the store.
   private static final boolean DEBUG = true;
   
   private RevMobAdsListener listener;
   
   private RevMobFullscreen fullscreenAd;
   private RevMobBanner bannerAd;
   
   private AndroidLauncher application;
   private RevMob revmob;
   
   public RevMobIntegration(AndroidLauncher _application) {
      this.application = _application;
      this.revmob = RevMob.start(application);
      if(DEBUG) {
         revmob.setTestingMode(RevMobTestingMode.WITH_ADS);
      }
     
      listener = new RevMobAdsListener() {

         @Override
         public void onRevMobAdClicked() {
            Log.i("[RevMob]", "Advertisement Clicked!");
            revmob.openAdLink(application, APPLICATION_ID, this);
            //showInterstitialAds(false);
         }

         @Override
         public void onRevMobAdDismiss() {
            Log.i("[RevMob]", "Advertisement Closed!");
            fullscreenAd.hide();
         }

         @Override
         public void onRevMobAdDisplayed() {
            Log.i("[RevMob]", "Advertisement Displayed!");
         }

         @Override
         public void onRevMobAdNotReceived(String message) {
            Log.i("[RevMob]", "No Advertisement Available!");
         }

         @Override
         public void onRevMobAdReceived() {
            Log.i("[RevMob]", "Advertisement Pulled from network!");
         }

         @Override
         public void onRevMobSessionIsStarted() {}
         @Override
         public void onRevMobSessionNotStarted(String arg0) {}
      };
     
      fullscreenAd = revmob.createFullscreen(application,
            APPLICATION_ID, listener);
      bannerAd = revmob.createBanner(application, APPLICATION_ID, listener);
      revmob.setTimeoutInSeconds(5);
   }
   
   @Override
   public void showInterstitialAds(boolean show) {
      if(show) {
         if(fullscreenAd == null) {
            fullscreenAd = revmob.createFullscreen(application,
                  APPLICATION_ID, listener);
            fullscreenAd.show();
         } else {
            fullscreenAd.show();
         }
      } else {
         fullscreenAd.hide();
      }
   }
   
   @Override
   public void showBannerAd(boolean show) {
      if(show) {
         if(bannerAd == null) {
            bannerAd = revmob.createBanner(application, APPLICATION_ID, listener);
         }
      } else {
         bannerAd.hide();
      }
   }
   
   public RevMobBanner getBannerAd() { return bannerAd; }
}


Now, go to your main class for the android project (in my case it's AndroidLauncher.java)

Search for

1  
protected void onCreate (Bundle savedInstanceState) {


Remove the line

1  
initialize(


and replace it with this.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
// Custom Init
      RevMobIntegration revmob = new RevMobIntegration(this);
      RelativeLayout bannerLayout = new RelativeLayout(this);
      RelativeLayout applicationLayout = new RelativeLayout(this);
      bannerLayout.setVisibility(View.GONE);
      float screenHeight = this.getWindowManager().getDefaultDisplay().getHeight();
      int bannerHeight = (int) (180/1920f*screenHeight);
     
      RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, bannerHeight);
     
      adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        adParams.addRule(RelativeLayout.CENTER_VERTICAL);
     
        bannerLayout.setLayoutParams(adParams);
       
        View gdxView = initializeForView(new TapoutGame(revmob), config);
        applicationLayout.addView(gdxView);
       
        if(revmob.getBannerAd() != null) {
           applicationLayout.addView(revmob.getBannerAd());
        }
       
        setContentView(applicationLayout);


This basically does everything that initialize does, however creates a relativelayout so we can draw the advertisement ontop of the LibGDX display. (I tried to override initialize, but it wouldn't work)


Make sure to replace "TapoutGame" with your games main class.  (in package com.company.game) in the core project

In the game class, add the following variable

1  
private static RevmobAdInterface adInterface;


Create the following constructors.

1  
2  
3  
4  
5  
6  
7  
public TapoutGame(RevmobAdInterface adInterface) {
      this.adInterface = adInterface;
   }

public TapoutGame( ) {

   }


Create a getter for the advertisements

1  
2  
3  
4  
   public RevmobAdInterface getAds() {
      return adInterface;
   }
   


Save, Compile. Complete.

Make sure to change your application id in RevMobIntegration.java.
Also, don't forget to import the Jar file and set it as a library (The RevMob instructions show you how to do this)

To show a fullscreen advertisement you simply call

1  
game.getAds().showInterstitialAds(true);
(from another class, considering game is what you called your instance of the main class)
or

1  
getAds().showInterstitalAds(true);
from the main class.

To disable the banner advertisement, simply comment out the line

1  
bannerAd = revmob.createBanner(application, APPLICATION_ID, listener);


in RevMobIntegration.java



Offline CTucker1327
« Reply #1 - Posted 2014-05-22 21:46:26 »

If you want to change the height of the Advertisement, in your android main class, look for

1  
   int bannerHeight = (int) (180/1920f*screenHeight); 


Edit the above to make changes.

Note, that there is some dead code at work here that I forgot to remove before posting..

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
@Override
   public void showBannerAd(boolean show) {
      if(show) {
         if(bannerAd == null) {
            bannerAd = revmob.createBanner(application, APPLICATION_ID, listener);
         }
      } else {
         bannerAd.hide();
      }
   }


in RevMobIntegration.java can be deleted, but you will have to remove

1  
    public void showBannerAd(boolean show);


in RevmobAdInterface.java

Offline Clepto

Senior Newbie


Exp: 3 years



« Reply #2 - Posted 2014-06-06 06:03:41 »

So I've been trying to get this working for about 3 days.

Whenever I open my app, it automatically crashes. Does nothing need to be done to handle the EULA acceptation that shows when you first launch the app?

Following Logcat, the error seems to be coming from when I start the RevMob session. It originates at the line in the RevMobIntegration class constructor:

1  
this.revmob = RevMob.start(application)


Java says that method is throwing a NullPointerException, but I can't for the life of me figure out what it is. Application doesn't appear to be null, and that seems to be the only thing going into it. I tried also running RevMob.startWithListener(application, listener) to no avail, same problem.

I'm assuming that this is due to something with the EULA, I don't know if this article is supposed to cover that(If it's like an automated process or something that I don't need to do anything with), but I can't even start the app at this point.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CTucker1327
« Reply #3 - Posted 2014-07-16 10:31:33 »

I'm honestly not sure what the problem is with your application, I haven't had any problems with my implementation. (And no, I don't use anything for the EULA, everything you see here is what I used)
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

PocketCrafter7 (14 views)
2014-11-28 16:25:35

PocketCrafter7 (9 views)
2014-11-28 16:25:09

PocketCrafter7 (10 views)
2014-11-28 16:24:29

toopeicgaming1999 (76 views)
2014-11-26 15:22:04

toopeicgaming1999 (67 views)
2014-11-26 15:20:36

toopeicgaming1999 (16 views)
2014-11-26 15:20:08

SHC (30 views)
2014-11-25 12:00:59

SHC (28 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (28 views)
2014-11-24 19:59:16
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!