Well… nm on the help. I think I have this one figured out. Google’s documentation assumes that you are extending the BaseGameActivity class and that just isn’t gonna happen. So, perhaps this will be useful to others:
Updates to Android Main Activity in prep of incorporating Google Play Services & Play Games Services:
[java]
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Games;
import com.jme3.app.AndroidHarness;
import com.jme3.system.android.AndroidConfigChooser.ConfigType;
import java.util.logging.Level;
import java.util.logging.LogManager;
import <PACKAGE NAME>.Main;
import <PACKAGE NAME>.JmeToHarness;
public class MainActivity extends AndroidHarness implements JmeToHarness, GameHelper.GameHelperListener {
public static final int CLIENT_GAMES = GameHelper.CLIENT_GAMES;
public static final int CLIENT_APPSTATE = GameHelper.CLIENT_APPSTATE;
public static final int CLIENT_PLUS = GameHelper.CLIENT_PLUS;
public static final int CLIENT_ALL = GameHelper.CLIENT_ALL;
private AdView adView;
private GoogleApiClient client;
private GoogleApiClient.Builder builder;
private GoogleApiClient.ApiOptions options = null;
private GameHelper mHelper;
protected int mRequestedClients = CLIENT_GAMES;
protected boolean mDebugLog = false;
public MainActivity(){
appClass = "<PACKAGE NAME>.Main";
eglConfigType = ConfigType.FASTEST;
exitDialogTitle = "Exit?";
exitDialogMessage = "Press Yes";
eglConfigVerboseLogging = false;
screenOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
mouseEventsEnabled = true;
LogManager.getLogManager().getLogger("").setLevel(Level.INFO);
splashPicID = R.drawable.<SPLASH SCREEN IMAGE NAME>;
}
@Override
public void onCreate(Bundle savedInstanceState) {
setRequestedClients(CLIENT_GAMES | CLIENT_APPSTATE);
if (mHelper == null)
getGameHelper();
super.onCreate(savedInstanceState);
mHelper.setup(this);
if (app != null)
((Main)app).setHarnessListener(this);
adView = new AdView(this);
adView.setAdSize(AdSize.FULL_BANNER);
adView.setAdUnitId("<YOUR AD UNIT ID>");
adView.buildLayer();
LinearLayout ll = new LinearLayout(this);
ll.setGravity(Gravity.BOTTOM);
ll.addView(adView);
addContentView(ll, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
@Override
public void update() {
super.update();
}
@Override
public void onDestroy() {
super.onDestroy();
System.runFinalization();
android.os.Process.killProcess(android.os.Process.myPid());
}
//************************//
// Base Game Activity Port
//************************//
protected void setRequestedClients(int requestedClients) {
mRequestedClients = requestedClients;
}
public GameHelper getGameHelper() {
if (mHelper == null) {
mHelper = new GameHelper(this, mRequestedClients);
mHelper.enableDebugLog(mDebugLog);
}
return mHelper;
}
@Override
protected void onStart() {
super.onStart();
mHelper.onStart(this);
}
@Override
protected void onStop() {
super.onStop();
mHelper.onStop();
}
@Override
protected void onActivityResult(int request, int response, Intent data) {
super.onActivityResult(request, response, data);
mHelper.onActivityResult(request, response, data);
}
protected GoogleApiClient getApiClient() {
return mHelper.getApiClient();
}
protected boolean isSignedIn() {
return mHelper.isSignedIn();
}
protected void beginUserInitiatedSignIn() {
mHelper.beginUserInitiatedSignIn();
}
protected void signOut() {
mHelper.signOut();
}
protected void showAlert(String message) {
mHelper.makeSimpleDialog(message).show();
}
protected void showAlert(String title, String message) {
mHelper.makeSimpleDialog(title, message).show();
}
protected void enableDebugLog(boolean enabled) {
mDebugLog = true;
if (mHelper != null) {
mHelper.enableDebugLog(enabled);
}
}
protected String getInvitationId() {
return mHelper.getInvitationId();
}
protected void reconnectClient() {
mHelper.reconnectClient();
}
protected boolean hasSignInError() {
return mHelper.hasSignInError();
}
protected GameHelper.SignInFailureReason getSignInError() {
return mHelper.getSignInError();
}
public void onSignInFailed() {
}
public void onSignInSucceeded() {
}
//************************//
// JmeToHarness methods
//************************//
public void unlockAchievement(String uid) {
if (mHelper.isSignedIn())
Games.Achievements.unlock(mHelper.getApiClient(), uid);
}
public void submitScore(String uid, long score) {
if (mHelper.isSignedIn())
Games.Leaderboards.submitScore(mHelper.getApiClient(), uid, score);
}
public void submitTime(String uid, long score) {
if (mHelper.isSignedIn())
Games.Leaderboards.submitScore(mHelper.getApiClient(), uid, score);
}
public void displayInterstitialAd() {
InterstitialAd interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("<YOUR AD UNIT ID>");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("<YOUR TEST DEVICE ID>")
.build();
interstitial.loadAd(adRequest);
}
public void displayBannerAd() {
runOnUiThread(new Runnable() {
public void run() {
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("<YOUR TEST DEVICE ID>")
.build();
adView.loadAd(adRequest);
adView.bringToFront();
adView.requestFocus();
}
});
}
}
[/java]
And here is JmeToHarness:
[java]
public interface JmeToHarness {
public void displayInterstitialAd();
public void displayBannerAd();
public void unlockAchievement(String uid);
public void submitScore(String uid, long score);
public void submitTime(String uid, long time);
}
[/java]
Likely you will want to disable auto-login in GameHelper.onStart() until you decide what you want to do with it.
Also note, this is by no means a final, however, it now compiles and runs properly with the above info about setting up the needed dependencies. Ignore the last post concerning something missing… it came down to setting up the helper options in onCreate before calling super.onCreate and then calling GameHelper.setup after the super call.
What I would like to eventually see incorporated into a plugin:
- Standard Leaderboard functionality (submits, top 10 retrieval and your placement)
- Standard Achievements functionality
- Cloud Save and Load (Would be nice if there was a some HashMap type data structure for storing user info, save games, etc that makes this simple method calls through the JmeToHarness interface)
- Possibly the addition of other common Ad services
- Facebook integration might be a valid option as well. Perhaps the entire plugin suite could consist of multiple integrations that are aware of each other?
Anyways, really looking forward to this becoming a plugin like the one available for Unity. Their’s is plug & play… no reason not to have this same sort of thing for JME.