Home > Software design >  data currect user on firebase android studio
data currect user on firebase android studio

Time:12-22

I try to do an app with Android Studio but I have a question and need help.

if I entered to the application with user - for example the user levana(i login to levana user with email and password)

and now I want to know my current user information (like email,firstname, password) how I do that? and what to write? and more question, if I want to know if levana is a kind of 'Help' user how I do that? and what to write?

thanks

i add picture to this question, and there is no need code because i see that i need only to work with commands declarations and function of firebase and database

enter image description here

edit :

    DatabaseReference db = 
    FirebaseDatabase.getInstance().getReference();
    DatabaseReference emailRef =db.child("Users").child("Help").child(FireLog.getCurrentUser().getEmail().replaceAll("\\.", ","));
    Log.e("Stringvalueschec", ""  emailRef.toString());
    DatabaseReference emailRef = db.child("Users").child("Help").child(FireLog.getCurrentUser().getEmail().replaceAll("\\.", ","));
    Log.e("Stringvalueschec", ""  emailRef.toString());

 
   Log.e("Stringvalueschec", ""  emailRef);

    emailRef.get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
        @Override
        public void onComplete(@NonNull Task<DataSnapshot> task) {
            if (task.isSuccessful()) {
                DataSnapshot snapshot = task.getResult();

                Configs.Pref_Email=snapshot.child("email").getValue(String.class);
                Configs.Pref_Email_Commas=snapshot.child("email").getValue(String.class).replaceAll("\\.", ",");;
                Configs.Pref_First_Name= snapshot.child("firstName").getValue(String.class);
                Configs.Pref_Last_Name= snapshot.child("lastName").getValue(String.class);
                Configs.Pref_Phone=snapshot.child("Phone").getValue(String.class);
                Configs.Pref_Password= snapshot.child("password").getValue(String.class);


                Log.e("Stringvalueschec", ""   Pref_Email   " "   Pref_Email_Commas   " "   Pref_First_Name   " "   Pref_Last_Name    " "   Pref_Phone  " "   Pref_Password);



            } else {
                Log.d("TAG", task.getException().getMessage()); //Don't ignore potential errors!
            }
        }
    });

CodePudding user response:

According to your comment, to get the data under levana@gmail,com, you have to create a reference that points exactly to the levana@gmail,com node and attach a listener on it. So please use the following lines of code:

DatabaseReference db = FirebaseDatabase.getInstance().getReference();
DatabaseReference emailRef = db.child("Users").child("Help").child("levana@gmail,com");
emailRef.get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
    @Override
    public void onComplete(@NonNull Task<DataSnapshot> task) {
        if (task.isSuccessful()) {
            DataSnapshot snapshot = task.getResult();
            String email = snapshot.child("email").getValue(String.class);
            Log.d("TAG", email); //Will print [email protected]
            String firstName = snapshot.child("firstName").getValue(String.class);
            Log.d("TAG", firstName); //           
  • Related