How can i check if user sign's out from games services default view?

后端 未结 3 2191
小鲜肉
小鲜肉 2020-12-30 17:17

I integrated google games services in my game, including Leaderboards and achievements. If the user opens the leaderboard or achievement activity, he has the possibility to

3条回答
  •  轮回少年
    2020-12-30 18:14

    In my case I am doing as following. On MainActivity ovveride onActivityResult(). RC_UNUSED is the requestCode when you call to open Leaderboards, Achievements and Settings activity from Google Play service app.

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
    if (requestCode == RC_UNUSED 
    && resultCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED) {
            signOut();
        }
    
        Log.i("test", "On Activity result called");
    }   
    

    Write your signOut() method as following

    public void signOut() {
        try {
            Games.signOut(mGoogleApiClient);
        }catch (SecurityException se){
            Log.i("test", "mGoogleApiClient status was disconnected when callin signOut status. message = " + se.getMessage());
        }
        if (mGoogleApiClient.isConnected()) {
            mGoogleApiClient.disconnect();
        }
        // update your UI logic here (show login btn, hide logout btn).
    }
    

    Don't forget to update your UI on the end of signOut()

提交回复
热议问题