i am trying to login using data that are stored in firebase realtime database and when i try to login with phone number it gives an error and the ondatachange function not working.
public class LoginActivity extends AppCompatActivity {
Button Log_in, sign_up;
CountryCodePicker countryCodePicker;
TextInputLayout number, password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Log_in = findViewById(R.id.Log_in);
sign_up = findViewById(R.id.sign_up);
number = findViewById(R.id.number);
password = findViewById(R.id.password);
countryCodePicker = findViewById(R.id.Login_ccp);
}
public void callHomrScreen(View view) {
if (!validateNumber() | !validatePassword()){
return;
}
//getting data
String _phoneNumber = number.getEditText().getText().toString().trim();
String _password = password.getEditText().getText().toString().trim();
if (_phoneNumber.charAt(0)=='0'){
_phoneNumber=_phoneNumber.substring(1);
}
String _completePhoneNumber = "+" + countryCodePicker.getFullNumber() + _phoneNumber;
//???DatabaseQuery
Query chekUser = FirebaseDatabase.getInstance().getReference("Users").orderByChild("phoneNumber").equalTo(_completePhoneNumber);
chekUser.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists()){
number.setError(null);
number.setErrorEnabled(false);
String systemPassword=snapshot.child(_completePhoneNumber).child("password").getValue(String.class);
if (systemPassword.equals(_password)){
password.setError(null);
password.setErrorEnabled(false);
}else{
Toast.makeText(LoginActivity.this, "Password Doesnot Exist!", Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(LoginActivity.this, "User Doesnot Exist!", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
Toast.makeText(LoginActivity.this, error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
public void callRegisterActivity(View view) {
startActivity(new Intent(getApplicationContext(), RegisterActivity.class));
}
private boolean validateNumber() {
String val = number.getEditText().getText().toString().trim();
if (val.isEmpty()) {
number.setError("field cannot be empty");
return false;
} else {
number.setError(null);
number.setErrorEnabled(false);
return true;
}
}
private boolean validatePassword() {
String val = password.getEditText().getText().toString().trim();
String checkPassword = "^" +
"(?=.*[0-9])" + //at least 1 digit
"(?=.*[a-z])" + //at least 1 lower case letter
"(?=.*[A-Z])" + //at least 1 upper case letter
"(?=.*[a-zA-Z])" + //any letter
"(?=.*[@#$%^&+=])" + //at least 1 special character
"(?=\\S+$)" + //no white spaces
".{4,}" + //at least 4 characters
"$";
if (val.isEmpty()) {
password.setError("field cannot be empty");
return false;
}
//else if (!val.matches(checkPassword)){
// password.setError("password should contain atleast 4 charecter");
// return false;
//}
else {
password.setError(null);
password.setErrorEnabled(false);
return true;
}
}
}
Error E/CCP: getFullNumber: Could not parse number E/CCP: getFullNumber: Could not parse number E/OpenGLRenderer: GL error: 0x506 A/OpenGLRenderer: GL errors! frameworks/base/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp:126 A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 9153 (RenderThread), pid 9112
countryCodePicker.getFullNumber()
? – Jatin