I am working on an application that has OTP screen integrated with it. There is one minor issue there. I have to check for two conditions, one is, if the network is not available then I have to display an error message that Network not available
. Else if user has entered a wrong OTP then then error message should say that 'Wrong OTP entered'.
Right now I am displaying a common message for both cases. No if else. I want to separate them into two. My problem is how do we check for Mobile network issue, if its available or not?
if (task.isSuccessful()) {
if (previousScreenTitle == R.string.login) {
userPrivateInfo = Constants.ALL_USERS_REFERENCE.child(userMobileNumber);
userPrivateInfo.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
/* Check if User mobile number is found in database */
if (dataSnapshot.exists()) {
startActivity(new Intent(OTP.this, NammaApartmentsHome.class));
}
/* User record was not found in firebase hence we navigate them to Sign Up page*/
else {
Intent intent = new Intent(OTP.this, SignUp.class);
intent.putExtra(Constants.MOBILE_NUMBER, userMobileNumber);
startActivity(intent);
}
finish();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else {
setResult(Activity.RESULT_OK, new Intent());
finish();
}
} else {
textResendOTPOrVerificationMessage.setText(R.string.check_network_connection);
}