firebase和synced的
我们在Android应用中添加Google登录所必须采取的步骤。
登录时出错。
<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="9dp"
android:layout_marginBottom="109dp" />
然后在主要活动中从GoogleSignInClient
获取实例通过此代码
public GoogleSignInClient mGoogleSignInClient;
然后在onCreate方法中初始化此对象
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
然后使用XML的onClick发送请求以使用“使用Gmail登录”,>
Intent signInIntent = mGoogleSignInClient.getSignInIntent(); startActivityForResult(signInIntent, 1);
最终覆盖OnActivityResult并通过以下方式获取userData:>
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { callbackManager.onActivityResult(requestCode,resultCode,data); super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...); if (requestCode == 1) { // The Task returned from this call is always completed, no need to attach // a listener. Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); } }