Google身份验证问题,同时显示所有包含图片的数据。不幸的是,没有图片应用的帐户停止了我不知道问题出在哪里。加上检查url是否为空会产生同样的错误。我正在关注它的Androidhive.info示例。
另外,google登录和Android注册谷歌有什么不同? 我自己学习Android,任何人都可以指出我做错了。 任何帮助表示赞赏。
public class Social extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.OnConnectionFailedListener {
private static final int RC_SIGN_IN = 007;
private GoogleApiClient mGoogleApiClient;
private ProgressDialog mProgressDialog;
private SignInButton btnSignIn;
private Button btnSignOut;
private LinearLayout llProfileLayout;
private ImageView imgProfilePic;
private TextView txtName, txtEmail;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_social);
btnSignIn = (SignInButton) findViewById(R.id.btnSignin);
btnSignOut = (Button) findViewById(R.id.btnSignOut);
llProfileLayout = (LinearLayout) findViewById(R.id.llProfile);
imgProfilePic = (ImageView) findViewById(R.id.imgProfilePic);
txtName = (TextView) findViewById(R.id.txtName);
txtEmail = (TextView) findViewById(R.id.txtEmail);
btnSignIn.setOnClickListener(this);
btnSignOut.setOnClickListener(this);
llProfileLayout.setVisibility(View.GONE);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();
mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, this).addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
}
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
private void signOut() {
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
updateUI(false);
}
});
}
private void handleSignInResult(GoogleSignInResult result) {
//Log.d(TAG, "handleSignInResult:" + result.isSuccess());
if (result.isSuccess()) {
// Signed in successfully, show authenticated UI.
try {
GoogleSignInAccount acct = result.getSignInAccount();
String personName = acct.getDisplayName();
String personPhotoUrl = acct.getPhotoUrl().toString();
String email = acct.getEmail();
//Toast.makeText(this, ""+personPhotoUrl, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Social.this, tester.class);
intent.putExtra("User", personName);
intent.putExtra("Email", email);
intent.putExtra("Pic", personPhotoUrl);
startActivity(intent);
}catch (Exception ep){
}
}
else {
startActivity(new Intent(Social.this, MainActivity.class));
finish();
// Signed out, show unauthenticated UI.
// updateUI(false);
}
}
@Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.btnSignin:
signIn();
break;
case R.id.btnSignOut:
signOut();
break;
//default:break;
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
// An unresolvable error has occurred and Google APIs (including Sign-In) will not
// be available.
// Log.d(TAG, "onConnectionFailed:" + connectionResult);
}
private void updateUI(boolean isSignedIn) {
if (isSignedIn) {
btnSignIn.setVisibility(View.GONE);
llProfileLayout.setVisibility(View.VISIBLE);
} else {
btnSignIn.setVisibility(View.VISIBLE);
llProfileLayout.setVisibility(View.GONE);
}
}
}