1

I have found a bunch of posts with similar issues but most are using BaseGameUtils or GoogleApiClient which I don't have. One suggested answer was to add, Games.setViewForPopups(getApiClient(), findViewById(R.id.gps_popup)); Which I can't do unless I have GoogleApiClient.

Achievement code:

public void achieve(String achievement) {
    Games.getAchievementsClient(this, signedInAccount).unlock(achievement);
}

public void increment(String achievement, int i) {
    Games.getAchievementsClient(this, signedInAccount).increment(achievement, i);
}

Sign In code:

@Override
protected void onCreate(Bundle _savedInstanceState) {
    ...
    signInSilently();
}

private void signInSilently() {
    GoogleSignInClient signInClient = GoogleSignIn.getClient(this, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
    signInClient.silentSignIn().addOnCompleteListener(this,
            new OnCompleteListener<GoogleSignInAccount>() {
                @Override
                public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
                    if (task.isSuccessful()) {
                        signedInAccount = task.getResult();
                        findViewById(R.id.achievements_btn).setVisibility(View.VISIBLE);
                    } else {
                        startSignInIntent();
                    }
                }
            });
}

private void startSignInIntent() {
    GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
            GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
    Intent intent = signInClient.getSignInIntent();
    startActivityForResult(intent, RC_SIGN_IN);
}

@Override
protected 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()) {
            signedInAccount = result.getSignInAccount();
            findViewById(R.id.achievements_btn).setVisibility(View.VISIBLE);
            Toast.makeText(getApplicationContext(), "Signed In", Toast.LENGTH_SHORT).show();
        } else {
            String message = result.getStatus().getStatusMessage();
            if (message == null || message.isEmpty()) {
                message = "Error";
            }
            Toast.makeText(getApplicationContext(), "Sign In Failed, please check internet connection and restart the app to use achievements.", Toast.LENGTH_LONG).show();
            cancelledSignIn = true;
        }
    }
}


private void showAchievements() {
    Games.getAchievementsClient(this, signedInAccount)
            .getAchievementsIntent()
            .addOnSuccessListener(new OnSuccessListener<Intent>() {
                @Override
                public void onSuccess(Intent intent) {
                    startActivityForResult(intent, RC_ACHIEVEMENT_UI);
                }
            });
}

Not sure what to do, this all has worked fine except the pop up never shows. I never had to use GoogleApiClient, if I do need to could you tell me why and how? All help would be greatly appreciated!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Matthew Vine
  • 120
  • 2
  • 16

2 Answers2

1

If you are testing the game services and Pop-ups are not showing for achievements, the reason could be that you have not added an ICON for that achievement. I have found, Popups are only shown for the achievements with ICON

Hammad
  • 1,268
  • 15
  • 27
0

I had the same problem and did not use BaseGameUtils or GoogleApiClient either.

I added the below to my OnConnected from this StackOverflow answer.

GamesClient gamesClient = Games.getGamesClient(MainActivity.this, 
GoogleSignIn.getLastSignedInAccount(context));
gamesClient.setViewForPopups(findViewById(R.id.gps_popup));

It gave a lint warning that GoogleSignIn.getLastSignedInAccount(this)) might be null so I just wrapped it in an if statement list this:

if(GoogleSignIn.getLastSignedInAccount(this) != null){
GamesClient gamesClient = Games.getGamesClient(MainActivity.this, 
GoogleSignIn.getLastSignedInAccount(context));
gamesClient.setViewForPopups(findViewById(R.id.gps_popup));
}

This may not be a great answer but it worked for me, so I hope that you can find it useful, Good Luck.

MDodd423
  • 23
  • 6
  • I tried this, also added that view block `gps_popup` in my main layout. I didn't get any errors but I also didn't see any pop-up. – Matthew Vine Aug 01 '18 at 12:45
  • @MattVine I moved the code from my `OnCreate` to `OnConnected` and it is working better. I tried moving it to different places during the Signin process and troubleshooted by Signing in and out of the app until it behaved as desired and the Google Play Games username would float over the view and disappear. – MDodd423 Aug 01 '18 at 16:16
  • I could not find `OnConnected`. Where do put `OnConnected` in my code? – Matthew Vine Aug 01 '18 at 19:18
  • @MattVine I believe we use a different technique for connecting to the Google Play Games Service. I followed the Google TypeANumber tutorial hosted on [Github](https://github.com/playgameservices/android-basic-samples) which includes an `OnConnected` function. You can also view the project I created while following the Google tutorial, that implements this fix, on Github [here](https://github.com/MDodd423/TapAttack). – MDodd423 Aug 01 '18 at 20:14