integrating googleplus in android fetch (gender and birthday)

只愿长相守 提交于 2019-12-08 02:47:51

问题


am trying to fetch gender and birthday from googleplus integration in android ... but getting gender as "0" please help me on this..am attaching my code ..please find the below code..birthday is showing as empty..

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mSignInButton = (SignInButton) findViewById(R.id.sign_in_button);

    mSignInButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

              mGoogleApiClient.connect();

        }
    });


    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_PROFILE)
            .addScope(Plus.SCOPE_PLUS_LOGIN).build();
}

protected void onStart() {
    super.onStart();
//  mGoogleApiClient.connect();



}

protected void onStop() {
    super.onStop();

    if (mGoogleApiClient.isConnected()) {
        mGoogleApiClient.disconnect();
    }
}

public void onConnectionFailed(ConnectionResult result) {
    if (!mIntentInProgress && result.hasResolution()) {
        try {
            mIntentInProgress = true;
            startIntentSenderForResult(result.getResolution()
                    .getIntentSender(), RC_SIGN_IN, null, 0, 0, 0);
        } catch (SendIntentException e) {

            mIntentInProgress = false;
            mGoogleApiClient.connect();
        }
    }
}



public void onConnected(Bundle connectionHint) {

    if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {

        Person currentPerson = Plus.PeopleApi
                .getCurrentPerson(mGoogleApiClient);
        String personName = currentPerson.getDisplayName();         

        try {
            int genderInt = currentPerson.getGender();
         String   gender     = String.valueOf(genderInt);
        String birthday = currentPerson.getBirthday();

        System.out.println("gender" + gender + "bod" + birthday);

        } 


        catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }       

        String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
    }
}

@Override
public void onConnectionSuspended(int cause) {
    mGoogleApiClient.connect();
}

protected void onActivityResult(int requestCode, int responseCode,
        Intent intent) {
    if (requestCode == RC_SIGN_IN) {
        mIntentInProgress = false;

        if (!mGoogleApiClient.isConnecting()) {
            mGoogleApiClient.connect();
        }
    }
}



@Override
public void onResult(LoadPeopleResult peopleData) {
    // TODO Auto-generated method stub
     if (peopleData.getStatus().getStatusCode() == CommonStatusCodes.SUCCESS) {
            PersonBuffer personBuffer = peopleData.getPersonBuffer();
            try {
              int count = personBuffer.getCount();
              for (int i = 0; i < count; i++) {
                Log.d(TAG, "Display name: " + personBuffer.get(i).getDisplayName());
              }
            } finally {
              personBuffer.close();
            }
          } else {
            Log.e(TAG, "Error requesting people data: " + peopleData.getStatus());
          }
}

}

回答1:


getGender() returns int.. 0 - Male, 1 - Female..

Reference: http://developer.android.com/reference/com/google/android/gms/plus/model/people/Person.html#getGender()



来源:https://stackoverflow.com/questions/27908362/integrating-googleplus-in-android-fetch-gender-and-birthday

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!