gpt4 book ai didi

取消时出现 Android Google 登录错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:35:51 25 4
gpt4 key购买 nike

我遇到了一些无法解决的奇怪问题。我有一个使用 Google 登录的 Android 应用程序。该应用程序遵循 MVP 模式并使用 fragment 而不是 Activity 。登录部分来自这里: https://developers.google.com/identity/sign-in/android/

一切正常,直到我尝试通过在其外部点击来关闭登录对话框(您在其中选择用户)。我假设它应该给我一个状态代码 12501 (SIGN_IN_CANCELLED) 但我得到的是代码 13 (ERROR)。我的假设错了吗?如果发生错误,我是否应该忽略代码 13 并且不向用户显示任何错误?

下面是最相关的代码

Activity :

public class SignInActivity extends AppCompatActivity implements SignInFragment.SignInListener {    

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);

// Add sign in fragment
mSignInFragment = new SignInFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager
.beginTransaction()
.replace(R.id.sign_in_frame, mSignInFragment, TAG)
.commit();
}

@Override
public void startSignIn() {
Intent signInIntent = mSignInFragment.getGoogleSignInClient().getSignInIntent();
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) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
mSignInFragment.handleSignInResult(task);
}
}
}

fragment :

public class SignInFragment extends DaggerFragment implements SignInContract.View, GoogleApiClient.OnConnectionFailedListener {

private SignInFragment.SignInListener signInListener;

public interface SignInListener {
void startSignIn();
void startMainActivity();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken( clientId )
.build();

mGoogleSignInClient = GoogleSignIn.getClient(getActivity(), gso);

// Calling this to force user select dialog to appear everytime
mGoogleSignInClient.signOut();

signInButton.setOnClickListener(v -> {
signInListener.startSignIn();
}
}

protected void handleSignInResult(Task<GoogleSignInAccount> task) {
try {
GoogleSignInAccount acct = task.getResult(ApiException.class);
String idToken = acct.getIdToken();
presenter.deliverTokenToServer(idToken);

} catch (ApiException e) {
e.printStackTrace();
Log.d(TAG, "handleSignInResult:" + e.getStatusCode());
Snackbar snackbar = Snackbar.make(getView(), R.string.error_login_failed_try_again, Snackbar.LENGTH_LONG);
snackbar.show();

}
}
}

在 gradle 文件中,我使用了 'com.google.android.gms:play-services-auth:15.0.1''com.google.gms:google-服务:4.0.1'

最佳答案

我终于找到了。这是 Google Play 库中的回归。并且它已在 play-services-auth:16.0.0 中修复。这是一些details .

implementation com.google.android.gms:play-services-auth:16.0.0

关于取消时出现 Android Google 登录错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51655696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com