.getCurrentPerson(mGoogleApiClient) 在 GooglePlayServices 8.4 中弃用

.getCurrentPerson(mGoogleApiClient) deprecated in GooglePlayServices 8.4

我正在学习关于将 Google 登录集成到 Android 应用程序的 Udacity 课程。因为我们尝试通过 onConnected() 中的 .getCurrentOerson() 获取当前用户的详细信息,但是 .getCurrentOerson() 已被弃用。

 public class SignInAct extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
GoogleApiClient mGoogleApiClient;
Button signIn,signOut,revoke;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.signinlay);
    mGoogleApiClient = buildApiClient();
}
GoogleApiClient buildApiClient(){
    return new GoogleApiClient.Builder(this).
            addConnectionCallbacks(this).
            addOnConnectionFailedListener(this).
            addApi(Plus.API, Plus.PlusOptions.builder().build()).
            addScope(new Scope(Scopes.PROFILE)).build();
}

    @Override
public void onConnected(Bundle bundle) {
    signIn.setEnabled(false);
    signOut.setEnabled(true);
    revoke.setEnabled(true);

    Person currentUser = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);

}}

现在如何获取displayName? 谢谢。

public abstract Person getCurrentPerson (GoogleApiClient googleApiClient) documentation:

This method is deprecated.

If you are using People Api simply for signing in and fetching identity, please use GoogleSignInApi instead.

From the GoogleSignInResult documentation:

public GoogleSignInAccount getSignInAccount()

Returns a GoogleSignInAccount reflecting the user's sign in information if sign-in completed successfully; or null when failed.

From the GoogleSignInAccount documentation:

public String getDisplayName()

Returns the display name of the signed in user if you built your configuration starting from new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)} or with requestProfile() configured; null otherwise. Not guaranteed to be present for all users, even when configured.