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