How to show the welcome popup on play games services?

Viewed 2026

I implement the google play game services on my game. I can connect on it but when I come back to my game, I can't show the welcome POPUP ... How can I show it ?

I tried the setViewForPopups and setGravityForPopups like they said on the documentation...

private void startSignInIntent() {
 GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
            .requestEmail()
            .build();
GoogleSignInClient signInClient = GoogleSignIn.getClient(getActivity(),
            gso);
    Intent intent = signInClient.getSignInIntent();
    startActivityForResult(intent, RC_SIGN_IN);
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            // The signed in account is stored in the result.
            GoogleSignInAccount signedInAccount = result.getSignInAccount();
            Games.getGamesClient(getContext(), signedInAccount).setViewForPopups(getView());
        } else {
            String message = result.getStatus().getStatusMessage();
            if (message == null || message.isEmpty()) {
                message = getString(R.string.signin_other_error);
            }
            new AlertDialog.Builder(getActivity()).setMessage(message)
                    .setNeutralButton(android.R.string.ok, null).show();
        }
    }
}
3 Answers

In order to show the "Welcome Back" popup, call this method when sign-in is successful.

ViewGroup vgContent = activity.findViewById(R.id.content);

GamesClient client = Games.getGamesClient(mContext, signedInAccount);
client.setViewForPopups(vgContent);
client.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);

Welcome back dialog is going to appear at the top of the screen. You can give either Context or Activity.

You will need to provide a view for a popup to appear. Here I am giving the activity's content view, which is always present.

Related