这允许我通过Gmail登录并显示其显示的图片,我的姓名等,但不能与其他随机人的ID一起使用。
我在developer.google.com上添加了更多所有者,并且允许他们,但我不允许。
=
public class MainActivity extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.OnConnectionFailedListener{
private LinearLayout Prof_Section;
private Button SignOut;
private SignInButton SignIn;
private TextView Name,Email;
private ImageView Prof_Pic;
private GoogleApiClient googleApiClient;
private static final int REQ_CODE=9001;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Prof_Section = (LinearLayout)findViewById(R.id.Prof_Section);
SignOut = (Button)findViewById(R.id.bn_logout);
SignIn = (SignInButton)findViewById(R.id.bn_login);
Name=(TextView)findViewById(R.id.name);
Email=(TextView)findViewById(R.id.email);
Prof_Pic=(ImageView) findViewById(R.id.prof_pic);
SignIn.setOnClickListener(this);
SignOut.setOnClickListener(this);
Prof_Section.setVisibility(View.GONE);
GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();
googleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this,this).addApi(Auth.GOOGLE_SIGN_IN_API,signInOptions).build();
}
@Override
public void onClick(View v) {
switch(v.getId())
{
case R.id.bn_login:
signIn();
break;
case R.id.bn_logout:
signOut();
break;
}
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
private void signIn()
{
Intent intent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
startActivityForResult(intent,REQ_CODE);
}
private void signOut()
{
Auth.GoogleSignInApi.signOut(googleApiClient).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
updateUI(false);
}
});
}
private void handleResult(GoogleSignInResult result)
{if(result.isSuccess())
{
GoogleSignInAccount account = result.getSignInAccount();
String name = account.getDisplayName();
String email = account.getEmail();
String img_url = account.getPhotoUrl().toString();
Name.setText(name);
Email.setText(email);
// Glide.with(this).load(img_url).into(Prof_Pic);
// Glide.with(this)
// .load(img_url)
// // .override(300, 200)
// .into(Prof_Pic);
// Glide.with(this).load(img_url).into(Prof_pic);
updateUI(true);
}
else
{updateUI(false);}
}
private void updateUI(boolean isLogin){
if(isLogin){
Prof_Section.setVisibility(View.VISIBLE);
SignIn.setVisibility((View.GONE));
}
else
{
Prof_Section.setVisibility(View.GONE);
SignIn.setVisibility(View.VISIBLE);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode,Intent data)
{
super.onActivityResult(requestCode,resultCode,data);
if(requestCode==REQ_CODE)
{
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleResult(result);
}
}
}
它记录我并显示我的详细信息,但不显示其他人的详细信息。 我希望他们尝试登录时也能提供详细信息
答案 0 :(得分:0)
SignInButton登录= findViewById(R.id。);
findViewById(R.id.bn_login).setOnClickListener(this);
findViewById(R.id.bn_login).setVisibility(View.GONE);