在android系统集成GOOGLEPLUS取(性别和生日) [英] integrating googleplus in android fetch (gender and birthday)

查看:319
本文介绍了在android系统集成GOOGLEPLUS取(性别和生日)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在android系统来从GOOGLEPLUS整合性别和生日...
    但得到的性别为0,请帮我this..am连接我的code ..please看到以下
    code..birthday是显示为空。

 公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);    mSignInButton =(SignInButton)findViewById(R.id.sign_in_button);    mSignInButton.setOnClickListener(新OnClickListener(){        @覆盖
        公共无效的onClick(视图v){
            // TODO自动生成方法存根              mGoogleApiClient.connect();        }
    });
    mGoogleApiClient =新GoogleApiClient.Builder(本)
            .addConnectionCallbacks(本)
            .addOnConnectionFailedListener(本).addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_PROFILE)
            .addScope(Plus.SCOPE_PLUS_LOGIN).build();
}保护无效调用onStart(){
    super.onStart();
// mGoogleApiClient.connect();}保护无效的onStop(){
    super.onStop();    如果(mGoogleApiClient.isConnected()){
        mGoogleApiClient.disconnect();
    }
}公共无效onConnectionFailed(ConnectionResult结果){
    如果(mIntentInProgress&放大器;!&放大器; result.hasResolution()){
        尝试{
            mIntentInProgress =真;
            startIntentSenderForResult(result.getResolution()
                    .getIntentSender(),RC_SIGN_IN,NULL,0,0,0);
        }赶上(SendIntentException E){            mIntentInProgress = FALSE;
            mGoogleApiClient.connect();
        }
    }
}公共无效onConnected(捆绑connectionHint){    如果(Plus.PeopleApi.getCurrentPerson(mGoogleApiClient)!= NULL){        人currentPerson = Plus.PeopleApi
                .getCurrentPerson(mGoogleApiClient);
        字符串PERSONNAME = currentPerson.getDisplayName();        尝试{
            INT genderInt = currentPerson.getGender();
         字符串性别=将String.valueOf(genderInt);
        字符串的生日= currentPerson.getBirthday();        的System.out.println(性别+性别+董事会+生日);        }
        赶上(例外五){
            // TODO自动生成catch块
            e.printStackTrace();
        }        字符串email = Plus.AccountApi.getAccountName(mGoogleApiClient);
    }
}@覆盖
公共无效onConnectionSuspended(INT原因){
    mGoogleApiClient.connect();
}保护无效的onActivityResult(INT申请code,INT响应code,
        意向意向){
    如果(要求code == RC_SIGN_IN){
        mIntentInProgress = FALSE;        如果(!mGoogleApiClient.isConnecting()){
            mGoogleApiClient.connect();
        }
    }
}@覆盖
公共无效onResult(LoadPeopleResult peopleData){
    // TODO自动生成方法存根
     如果(peopleData.getStatus()的getStatus code()== CommonStatus codes.SUCCESS){
            PersonBuffer personBuffer = peopleData.getPersonBuffer();
            尝试{
              诠释计数= personBuffer.getCount();
              的for(int i = 0; I<计数;我++){
                Log.d(TAG显示名称:+ personBuffer.get(I).getDisplayName());
              }
            } {最后
              personBuffer.close();
            }
          }其他{
            Log.e(TAG,错误请求人数据:+ peopleData.getStatus());
          }
}}


解决方案

getGender()返回INT ..
0 - 男,1 - 女性。

参考:<一href=\"http://developer.android.com/reference/com/google/android/gms/plus/model/people/Person.html#getGender()\" rel=\"nofollow\">http://developer.android.com/reference/com/google/android/gms/plus/model/people/Person.html#getGender()

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());
          }
}

}

解决方案

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

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

这篇关于在android系统集成GOOGLEPLUS取(性别和生日)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆