0

i'm developing a simple turn card game with Google Play Games Services. For building the Google Client, i use this Snippet:

public class App extends Application {
private GoogleApiClient mGoogleApiClient;
public AppCompatActivity activity;

public synchronized GoogleApiClient getGoogleApiClient(AppCompatActivity activity, GoogleApiClient.ConnectionCallbacks callbacks , GoogleApiClient.OnConnectionFailedListener listener){
    this.activity = activity;
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this.activity, listener)
            .addConnectionCallbacks(callbacks)
            .setViewForPopups(activity.getWindow().getDecorView().getRootView())
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            .build();
    return mGoogleApiClient;
}

It's work fine, i can connect both from my account and from tester.
Now i want to sent a special notification to the client when another user send an invitation. The first step i made is to register a ConnectionListner to Client:

public class LoginActivity extends AppCompatActivity implements View.OnClickListener,OnInvitationReceivedListener,GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener {
...
GoogleApiClient mGoogleApiClient;
 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    //Get google api client
   mGoogleApiClient = ((App) getApplication()).getGoogleApiClient(LoginActivity.this, this, this);
...
}

On Client API Connect i register the invitationListner with code:

 @Override
    public void onConnected(@Nullable Bundle bundle) {
        Log.d(TAG,"connesso");
        Games.Invitations.registerInvitationListener(mGoogleApiClient, this);
    }

For invite the other user, i use the code found in Api Examples:

    final ArrayList<String> invitees = data
                .getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);

        Log.d(TAG,"Invites find:"+invitees.get(0).toString());
        // get automatch criteria
        Bundle autoMatchCriteria = null;

        int minAutoMatchPlayers = data.getIntExtra(
                Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 1);
        int maxAutoMatchPlayers = data.getIntExtra(
                Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 1);

        if (minAutoMatchPlayers > 0) {
            autoMatchCriteria = RoomConfig.createAutoMatchCriteria(
                    minAutoMatchPlayers, maxAutoMatchPlayers, 0);
        } else {
            autoMatchCriteria = null;
        }

        TurnBasedMatchConfig tbmc = TurnBasedMatchConfig.builder()
                .addInvitedPlayers(invitees)
                .setAutoMatchCriteria(autoMatchCriteria).build();

        // Start the match
        Games.TurnBasedMultiplayer.createMatch(mGoogleApiClient, tbmc).setResultCallback(...);});

For Receive the invite of user simply override the standard function:

 @Override
public void onInvitationReceived(Invitation invitation) {
    Log.d(TAG,"invito arrivato");
}

The Users selectors work's fine; i'm sure of this because in Google Play Games App on the smartphones i see the request. But the invitation Received Log is never called.

Where am I doing wrong?? Thanks in advance

giuseppe trubia
  • 142
  • 1
  • 13
  • Try comparing your code to the [Google sample](https://github.com/playgameservices/android-basic-samples/blob/07a358c94b09f2ea2f1f844cf904009fd6d7b5e2/BasicSamples/SkeletonTbmp/src/main/java/com/google/example/tbmpskeleton/SkeletonActivity.java) and check if you have the same implementation.Make sure your accounts are registered as tester, if not they will not be able to receive the invitation as stated in this SO [post](http://stackoverflow.com/a/16907282/5995040). – Mr.Rebot Mar 23 '17 at 06:42
  • @Mr.Rebot the code is the same. If my accounts aren't trusted tester i get an error when i try to invite – giuseppe trubia Mar 23 '17 at 15:52

0 Answers0