I'm trying to create an app if someone want to use my app they must create a user. When they register they will insert first name, last name, phone and email address. After I confirm that the phone is theirs by using Firebase authorization I want to insert his data to a table named Users in my RealTime Database.
When I tried to do it by using this function:
**EDIT: I added the onComplete function but it doesn't execute **
private void storeNewUserData() {
FirebaseDatabase rootNode = FirebaseDatabase.getInstance();
DatabaseReference reference = rootNode.getReference("Users");
User user = new User(phone,firstName,lastName,email);
reference.setValue(user).addOnCompleteListener(this);
}
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
Toast.makeText(this, "Inserted User: "+phone+firstName+lastName+email, Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(this, task.getException().toString(), Toast.LENGTH_SHORT).show();
}
}
The database has not been updated but the Toast appeared (with all the data).
I don't think there is a problem in my code maybe it's a problem in my Firebase account.. Anyway I add the rules to this database and an image of the table.
Rules
{
"rules": {
".read": "true",
".write": "true"
}
}
build.gradle(app)
dependencies {
implementation platform('com.google.firebase:firebase-bom:26.8.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-auth:20.0.3'
implementation 'com.google.firebase:firebase-database:19.7.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.browser:browser:1.3.0"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
}
';
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
progressDialog.dismiss();
User user = new User(phone,firstName,lastName,email);
storeNewUserData();
Toast.makeText(PhoneAuthActivity.this, "Logged in as "+phone, Toast.LENGTH_SHORT).show();
startActivity(new Intent(PhoneAuthActivity.this, MainActivity.class));
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
progressDialog.dismiss();
Toast.makeText(PhoneAuthActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
logcat
2021-03-30 03:41:02.326 15207-15345/com.example.teorialearning E/FirebaseAuth: [GetAuthDomainTask] Error getting project config. Failed with INVALID_CERT_HASH 400
2021-03-30 03:41:02.344 15207-15257/com.example.teorialearning V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 396
2021-03-30 03:41:02.345 15207-15257/com.example.teorialearning V/FA: Activity paused, time: 15824705
2021-03-30 03:41:02.389 15207-15207/com.example.teorialearning E/zzf: Failed to get reCAPTCHA token with error [There was an error while trying to get your package certificate hash.]- calling backend without app verification
2021-03-30 03:41:02.391 15207-15257/com.example.teorialearning V/FA: Activity resumed, time: 15824751
2021-03-30 03:41:02.395 15207-15245/com.example.teorialearning W/System: Ignoring header X-Firebase-Locale because its value was null.
2021-03-30 03:41:02.641 15207-15207/com.example.teorialearning D/MAIN_TAG: onCodeSent:ALiwoWIdFZrl9ResXiUM94aPJW-csmRjdDOqoa9DTOkNQbv2Vf8YN7X6mvBwXgg9MJxEnFUVoE2rWAP2JzpT8QdBcRK2kIi82e_uO3pXW_rC5CZqWgJaqYqPO6nMOxiavmaJELnkSRtTXo6HoYoEY2_CmtVplEbz2Q
2021-03-30 03:41:02.644 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:02.677 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:02.739 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:04.679 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:04.789 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:07.416 15207-15257/com.example.teorialearning V/FA: Inactivity, disconnecting from the service
2021-03-30 03:41:08.627 15207-15245/com.example.teorialearning W/System: Ignoring header X-Firebase-Locale because its value was null.
2021-03-30 03:41:08.668 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:08.685 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:08.691 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:08.696 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:08.755 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:08.936 15207-15245/com.example.teorialearning W/System: Ignoring header X-Firebase-Locale because its value was null.
2021-03-30 03:41:09.147 15207-15245/com.example.teorialearning D/FirebaseAuth: Notifying id token listeners about user ( QgYB9guxYgT2AQbr8u9CVrGnELw2 ).
2021-03-30 03:41:09.149 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:09.178 15207-15257/com.example.teorialearning V/FA: Recording user engagement, ms: 6787
2021-03-30 03:41:09.180 15207-15257/com.example.teorialearning V/FA: Connecting to remote service
2021-03-30 03:41:09.181 15207-15257/com.example.teorialearning V/FA: Activity paused, time: 15831539
2021-03-30 03:41:09.189 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:09.193 15207-15257/com.example.teorialearning V/FA: Connection attempt already in progress
2021-03-30 03:41:09.212 15207-15225/com.example.teorialearning V/FA: onActivityCreated
2021-03-30 03:41:09.229 15207-15257/com.example.teorialearning V/FA: Activity resumed, time: 15831590
2021-03-30 03:41:09.233 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:09.243 15207-15257/com.example.teorialearning V/FA: Connection attempt already in progress
2021-03-30 03:41:09.244 15207-15257/com.example.teorialearning V/FA: Connection attempt already in progress
2021-03-30 03:41:09.295 15207-15257/com.example.teorialearning D/FA: Connected to remote service
2021-03-30 03:41:09.296 15207-15257/com.example.teorialearning V/FA: Processing queued up service tasks: 4
2021-03-30 03:41:09.298 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:09.329 15207-15207/com.example.teorialearning W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
2021-03-30 03:41:09.330 15207-15207/com.example.teorialearning W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
2021-03-30 03:41:11.206 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:13.170 15207-15333/com.example.teorialearning D/EGL_emulation: eglMakeCurrent: 0xae4856c0: ver 3 1 (tinfo 0xae483990)
2021-03-30 03:41:14.310 15207-15257/com.example.teorialearning V/FA: Inactivity, disconnecting from the service
2021-03-30 03:42:02.393 15207-15348/com.example.teorialearning W/FirebaseAuth: [SmsRetrieverHelper] Timed out waiting for SMS.
P.S: I'm using Android studio