Firebase电子邮件+密码登录事件未触发
问题描述:
我在登录和注册Firebase事件时遇到问题。代码跳过整个事件。Firebase电子邮件+密码登录事件未触发
public class LoginFragment extends Fragment {
String TAG = "LOGIN";
TextView tvLoginError;
EditText etUsername, etPassword;
Button btnLogin;
public LoginFragment() {}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.login, container, false);
setupTools(rootView);
return rootView;
}
private void setupTools(View rootView){
tvLoginError = (TextView) rootView.findViewById(R.id.tvLoginError);
etUsername = (EditText) rootView.findViewById(R.id.etUsername);
etPassword = (EditText) rootView.findViewById(R.id.etPassword);
btnLogin = (Button) rootView.findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final String username = etUsername.getText().toString();
final String password = etPassword.getText().toString();
// login
Authenticate.mAuth.signInWithEmailAndPassword(username, password).addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithEmail:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds the auth state listener will be notified and logic to handle the signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithEmail", task.getException());
tvLoginError.setText("Login failed - " + task.getException().getMessage().toString());
}
}
});
}
});
}
}
Authenticate.mAuth不为空。用户名和密码已设置。
没有错误,它只是完全跳过signInWithEmailAndPassword
中的onComplete
函数。我的AuthStateListener
事件Authentication
被触发onResume
在Authentication
(用户已注销,因为我无法注册或登录)。
我在我的清单中也有互联网许可。
答
原来我的代码没有错,但是我的google_services.json文件不正确(不知道为什么,我从中获得了此信息在设置Firebase身份验证后,Firebase/Google)。我最终通过更改Firebase中的设置来刷新它,然后恢复该设置并再次下载google_services.json。那有效..奇怪。