【发布时间】:2021-12-25 06:15:06
【问题描述】:
我只是想向用户显示错误,如果他输入了错误的 otp,我该如何实现,因为如果他输入了错误的代码,应用程序就会崩溃。
这是我的代码:
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
auth.signInWithCredential(credential).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
proceedProgressDialog.dismiss();
FirebaseUser user = auth.getCurrentUser();
String currentUserMobile = user.getPhoneNumber();
CollectionReference reference = FirebaseFirestore.getInstance().collection("Users");
Query query = reference.whereEqualTo("Mobile", currentUserMobile);
query.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (DocumentSnapshot snapshot : task.getResult()) {
String userCred = snapshot.getString("Mobile");
if (userCred.equals(currentUserMobile)) {
if (user != null) {
SharedPreferences.Editor editor = preferences.edit();
editor.putString(KEY_MOBILE, currentUserMobile);
editor.commit();
Intent intent = new Intent(LoginActivity.this, DashboardActivity.class);
startActivity(intent);
finishAffinity();
}
}
}
}
if (task.getResult().size() == 0) {
Toast.makeText(LoginActivity.this, "User Not Exist", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginActivity.this, AdditionalDetailsActivity.class);
startActivity(intent);
finish();
}
}
});
} else {
// Here I want to show wrong otp error
}
}
});
}
我想检查是否有人输入了错误的 otp 可能会显示错误
【问题讨论】:
-
如果应用程序崩溃,它会在 logcat 输出中记录带有消息和堆栈跟踪的异常。找到这些并将它们添加到您的问题中,以便我们了解问题所在。
-
现在我的应用程序没有崩溃,为什么我的应用程序之前崩溃了,但目前它运行良好
标签: java android google-cloud-firestore firebase-authentication