google-play-game-services-ane
google-play-game-services-ane copied to clipboard
No one uses the ANE anymore?
Please I really need some help. I don't know if its the ANE that is broken or if I am doing something wrong. I got everything to work except when I call on Show Leaderboards the game crashes immediately
I'm trying to use this Ane project, and, for example, after the SignIn activity, it always fail the login ( without showing any alert message, just checking the callbacks from flash and loggin into the android LogCat). Seems that is not able to perform the login. maybe it crashes because you are not logged in
Yeah that might be it. It prompts me to sign in and I do it loads and i guess signs me in. It doesnt crash after that or anything. But right when i call the leaderboards it crashes :/
Do I need Flex SDK for this ANE? I dont use it I hope thats not the reason.
Well, i'm using the Adobe Flash CC 2014, using the Air 16.0 for Android, it automatically keep his own sdk compiler, but i downloaded the the flex sdk 4.6 from the official website, and i'm using that one. Anyway, i just figure out how to perform the login with success. As also the GameHelper says on failure, you have to:
- check if the package name match the one used on the Google Developer console (eg. air.com.example.myapp, where the prefix 'air' is added automatically by adobe -.-" ) then be sure that the APP_ID is set properly into the manifest
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="\ your_app_id" />
(put the '\ ' before the code, this make the app id number interpreted as string)
And now, the magic part ( i didn't know honestly ). Reading on the https://developers.google.com/games/services/android/troubleshooting I was following the steps to figure out the issue, when i saw that, under the section Linked apps (reachable from the left menu at Google services > Your App > ) i discovered that there was just one Linked app, and his details shown me the WRONG associated OAuth2 Client ID. In order to make it works ( lets say, you have two certificate, debug and release ) you have to create two OAuth2 Client ID with the SHA1 Fingerprint for each certificate in the developer console (at https://console.developers.google.com/), and then add the link to each of them (at https://play.google.com/apps/publish). Seems crazy for me, but now sign in perfectly.
I'm going to test the rest of the app. I'm testing on a Samsung Galaxy Note 3 with Android 5.0
@NathanFitchett a lot of time was gone since I last comitted to my ANE... but now I return and great changes are waiting! Stay tuned...
@alextel69 great to hear that
@alextel69 cant wait!
I wrote this function for getting the list of Leaderboards, without showing them
public static class getAllLeaderboardInfo implements FREFunction {
@Override
public FREArray call(FREContext context, FREObject[] args) {
final String jsResultFailed = "{\"result\":0}";
if (SignInActivity.mHelper == null || !SignInActivity.mHelper.isSignedIn()){
context.dispatchStatusEventAsync("LOG_MSG", "No user is logged in Game Service");
// notify error
context.dispatchStatusEventAsync("LEADERBOARD_MSG_RESULT", jsResultFailed);
return null;
}
boolean fullLoad = false; // set to 'true' to reload all leaderboards (ignoring cache)
try {
fullLoad = args[0].getAsBool();
} catch (Exception e){
}
PendingResult<Leaderboards.LeaderboardMetadataResult> p = Games.Leaderboards.loadLeaderboardMetadata(SignInActivity.mHelper.getApiClient(), fullLoad);
p.setResultCallback(new ResultCallbackct<Leaderboards.LeaderboardMetadataResult>() {
@Override
public void onResult(Leaderboards.LeaderboardMetadataResult metaResults) {
int status = metaResults.getStatus().getStatusCode();
if ( status != GamesStatusCodes.STATUS_OK ) {
metaResults.release();
// notify error
context.dispatchStatusEventAsync("LEADERBOARD_MSG_RESULT", jsResultFailed);
return;
}
// process loaded leaderboards
LeaderboardBuffer buf = metaResults.getLeaderboards();
int bufSize = buf.getCount();
JSONArray jsArrayResult = new JSONArray();
// Composing result flash array with structure [{"leaderboard_id":"<String Value>","leaderboard_name":"<String Value>",...,{..}]
for ( int i = 0; i < bufSize; i++ ) {
Leaderboard leaderboardX = buf.get( i );
String lId = leaderboardX.getLeaderboardId();
String lName = leaderboardX.getDisplayName();
JSONObject jsLeaderboardX = new JSONObject();
try{
jsLeaderboardX.put("leaderboard_id", lId);
jsLeaderboardX.put("leaderboard_name", lName);
jsArrayResult.put(jsLeaderboardX);
}catch(Exception e){
}
}
JSONObject jsResultSuccess = new JSONObject();
try{
jsResultSuccess.put("result", 1);
jsResultSuccess.put("list", jsArrayResult);
}catch(Exception e){
}
// notify success
context.dispatchStatusEventAsync("LEADERBOARD_MSG_RESULT", jsResultSuccess.toString());
}
});
return null;
}
}
The sample dispatched message to catch on Flash side is a json string like the following:
{"result":1,"list":[{"leaderboard_id":"CgaI1zzALOAeEAIQAZ","leaderboard_name":"Leaderboard Display Name"}]}
Could be useful if we have a single leaderboard and want to send a score without knowing the leaderboard id. In this way, we can also "reset" the leaderboard just deleting it from the Google Developer console, and creating a new one, so this function will give us the list of existing leaderboards, and for instance, we can take always the first leaderboard id from the returned list
PS: the same approach can be performed with the Achievements
Hi, I did setup my leader board, all is working. My issue is that after closing the leader board activity, I am unable to interact with my app. Its seams that the activity keeps overlapping the app, I need to press the Back btn again to be able to interact with my app.
After that, the leader boar wont show anymore, just the translucent activity overlapping the app.
Can anyone help me with? thanks
@scionGbh I've had something similar not sure if it's the same, any chance you are listening for Event.DEACTIVATE and Event.ACTIVATE in your game ? If so remove them both and check if it will start working fine, if it will make an exception for leaderboard.
@scionGbh in the native java code (file: StubActivity.java) the method 'finish()' is missed, doing like the following made the trick for me:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE && resultCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED) {
SignInActivity.mHelper.onDisconnectedFromGoogleActivity();
}
finish();
}
@LucaIaco Thanks for your answer. can you please point me to the right way to rebuild the ane? I have import the project in eclipse and its full of errors by missing some classes (all FRE....)
thanks
You have to:
- ensure that at least no syntax error occurs in eclipse
- ensuring you have Apache 'ant'. If you haven't get here: http://ant.apache.org/srcdownload.cgi
- you need java installed on your machine
- open the terminal and go the folder which contains the build.xml file and, if all the path parameters are properly set (see the build.bat in this project, used on MS Windows i guess ) just run the 'ant' command (put the full path to the ant executable or add the environment variable for the ant executable file). If the script complete fine, you will get your custom version of the ANE file for this project. You can find plenty of examples online ( like https://github.com/alebianco/ANE-Google-Analytics ) and you will see that each one has a different implementation into the file 'build.xml' but the result will be almost the same.
@LucaIaco thanks so much, but I did tried adding the finish to the java class and recompile the ANE, but the issue is still there :(
@scionGbh mmm, pretty weird, i'll check tomorrow if i made something more maybe, normally calling 'finish()' the stub activity which manage the leaderboard / achievement presentation is dismissed ( it's transparent since there is no view attached to this activity at that state )
@LucaIaco Thanks, I am a half way to the solution. I did added the onPause() method and call the finish from there, that solved the first issue, when you close the leader board, keeping the activity overlapping the app.
But after that the app is unable to show back the leader board and just open the transparent activity overlapping the app.
@Override protected void onPause() { super.onPause(); finish(); }
I have been working on other projects since the last comment. Today I am back and I have managed to solve my issues.
as @LucaIaco suggested to me I have added the finish() method call to the StubActivity.
but I did it inside the onPause() method, that solved halve of my issue. now I did read the StubActivity class completely and solve both of my issues by setting isShown = false; before call finish().
@Override protected void onPause() { super.onPause(); isShown = false; StubActivity.this.finish(); }
no my StubActivity looks like this:
package com.google.api.games;
import android.app.Activity; import android.content.Intent; import android.os.Bundle;
import com.google.android.gms.games.Games; import com.google.android.gms.games.GamesActivityResultCodes;
public class StubActivity extends Activity {
public static final String ACTION_SHOW_LEADERBOARDS_ACTIVITY = "showLeaderboardsActivity";
public static final String ACTION_SHOW_LEADERBOARD_BY_ID_ACTIVITY = "showLeaderboardByIdActivity";
public static final String ACTION_SHOW_ACHIEVEMENTS_ACTIVITY = "showAchievementsActivity";
public static final String EXTRA_LEADERBOARD_ID = "extraLeaderboardId";
private static boolean isShown;
private static final int REQUEST_CODE = 7325;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isShown) {
return;
}
if (getIntent().getAction().equals(ACTION_SHOW_ACHIEVEMENTS_ACTIVITY)) {
startActivityForResult(
Games.Achievements.getAchievementsIntent(SignInActivity.mHelper
.getApiClient()), REQUEST_CODE);
}
else if (getIntent().getAction().equals(
ACTION_SHOW_LEADERBOARDS_ACTIVITY)) {
startActivityForResult(
Games.Leaderboards.getAllLeaderboardsIntent(SignInActivity.mHelper
.getApiClient()), REQUEST_CODE);
}
else if (getIntent().getAction().equals(
ACTION_SHOW_LEADERBOARD_BY_ID_ACTIVITY)) {
String leaderboardId = getIntent().getStringExtra(
EXTRA_LEADERBOARD_ID);
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(
SignInActivity.mHelper.getApiClient(), leaderboardId),
REQUEST_CODE);
}
isShown = true;
}
@Override
protected void onPause() {
super.onPause();
isShown = false;
StubActivity.this.finish();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE
&& resultCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED) {
SignInActivity.mHelper.onDisconnectedFromGoogleActivity();
}
}
}
Thanks all of you for your help, I hope my solution can help all of you. :)