无法在发布版apk中注册Google plus Android
我无法在我的android应用程序中注册google plus。在果冻豆和kitkat中效果很好。它在棒棒糖和更高版本中不起作用 我在Google SignInResult result.success()中出错 下面是我的代码:无法在发布版apk中注册Google plus Android,android,Android,我无法在我的android应用程序中注册google plus。在果冻豆和kitkat中效果很好。它在棒棒糖和更高版本中不起作用 我在Google SignInResult result.success()中出错 下面是我的代码: public class SignUp extends FragmentActivity implements GoogleApiClient.OnConnectionFailedListener { private ImageView
public class SignUp extends FragmentActivity implements
GoogleApiClient.OnConnectionFailedListener {
private ImageView google_button
private GoogleApiClient mGoogleApiClient;
private static final String TAG = "SignInActivity";
private static final int RC_SIGN_IN = 9001;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestProfile()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
//initializes view
initializeViews();
//facebook login end
google_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, 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);
Log.e("data g+", result.toString());
handleSignInResult(result);
}
}
private void handleSignInResult(GoogleSignInResult result) {
Log.e(TAG, "handleSignInResult:" + result.isSuccess());
if (result.isSuccess()) {
// Signed in successfully, show authenticated UI.
GoogleSignInAccount acct = result.getSignInAccount();
Log.e("authType", "googlePlus");
Log.e("authId", acct.getId());
Log.e("firstname", acct.getDisplayName());
Log.e("middlename", acct.getDisplayName());
Log.e("lastname", acct.getDisplayName());
Log.e("userpic", acct.getPhotoUrl() + "");
Log.e("email", acct.getEmail());
String[] DisplayName = acct.getDisplayName().split(" ");
String firstName = "";
String lastName = "";
if (DisplayName.length == 2) {
firstName = DisplayName[0];
lastName = DisplayName[1];
} else {
firstName = acct.getDisplayName();
}
String photoUrl = "";
if (acct.getPhotoUrl() != null) {
photoUrl = acct.getPhotoUrl().toString();
}
Bundle data = new Bundle();
data.putString("authType", "googlePlus");
data.putString("authId", acct.getId());
data.putString("firstname", firstName);
data.putString("middlename", "");
data.putString("lastname", lastName);
data.putString("userpic", photoUrl);
data.putString("email", acct.getEmail());
Intent intent = new Intent(SignUp.this, Register.class);
intent.putExtras(data);
startActivity(intent);
finish();
} else {
// Signed out, show unauthenticated UI.
}
}
@Override
protected void onStart() {
super.onStart();
}
@Override
protected void onStop() {
super.onStop();
}
public void initializeViews() {
register = (TextView) findViewById(R.id.register);
fb_button = (ImageView) findViewById(R.id.facebook_button);
google_button = (ImageView) findViewById(R.id.google_button);
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.e("connectionResult", connectionResult.toString());
Toast.makeText(getApplicationContext(), getResources().getString(R.string.server_error), Toast.LENGTH_SHORT).show();
}
}