Bom dia pessoal, preciso de um help
Estou programando com o android studio com o firebase.
Eu consigo realizar a auth normalmente aparece os logins dentro do firebase pelo o cadastro
o problema é que queria enviar os id para o realtime porém ele não envia nenhum informação,
package com.iot.mototaxi;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class PassageiroActivity extends AppCompatActivity {
private EditText mloginText,mSenhaText;
private Button mLogin,mCadastro;
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_passageiro2);
mloginText = findViewById(R.id.loginText);
mSenhaText = findViewById(R.id.senhaText);
mLogin = findViewById(R.id.login);
mCadastro = findViewById(R.id.cadastro);
mLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mAuth = FirebaseAuth.getInstance();
logar(mloginText.getText().toString(),mSenhaText.getText().toString());
}
});
mCadastro.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mAuth = FirebaseAuth.getInstance();
cadastro(mloginText.getText().toString(),mSenhaText.getText().toString());
}
});
}
public void updateUI(FirebaseUser account) {
if (account != null) {
Toast.makeText(this, "U Signed In successfully", Toast.LENGTH_LONG).show();
startActivity(new Intent(this, PassageiroLoginActivity.class));
} else {
Toast.makeText(this, "U Didnt signed in", Toast.LENGTH_LONG).show();
}
}
public void logar(String login,String password){
mAuth.signInWithEmailAndPassword(login, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d("Sucesso", "signInWithEmail:success");
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w("Error", "signInWithEmail:failure", task.getException());
Toast.makeText(PassageiroActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
updateUI(null);
}
// ...
}
});
}
public void cadastro (String login,String password) {
mAuth.createUserWithEmailAndPassword(login, password).addOnCompleteListener(PassageiroActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d("Sucesso", "createUserWithEmail:success");
String user_id = mAuth.getCurrentUser().getUid();
DatabaseReference current_user_db = FirebaseDatabase.getInstance().getReference().child("Users").child("Passageiro").child(user_id);
current_user_db.setValue(true);
} else {
// If sign in fails, display a message to the user.
Log.w("Error", "createUserWithEmail:failure", task.getException());
Toast.makeText(PassageiroActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
updateUI(null);
}
}
});
}
}
Segue meu build.gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0'
//implementation 'androidx.annotation:annotation:1.1.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-database:19.2.1'
implementation 'com.google.firebase:firebase-core:17.2.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}