This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

How to display username and email from firebase in android  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;

import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
import com.s.attendancemanagementsystem.R;


public class ProfileActivity extends AppCompatActivity {

   private static final String TAG = ProfileActivity.class.getSimpleName();
   Button logout;
   ImageView profilePic;
   private static int PICK_IMAGE = 500;
   private Uri imagePath;
   private TextView username_profile,user_email;
   private FirebaseAuth firebaseAuth;
   private DatabaseReference databaseReference;
   private FirebaseUser firebaseUuser;
   String uId;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_profile);

       username_profile = findViewById(R.id.username_profile_student);
       user_email = findViewById(R.id.email_profile_student);
       //initializing firebase authentication object
       firebaseAuth = FirebaseAuth.getInstance();

       databaseReference = FirebaseDatabase.getInstance().getReference();

       Query q = databaseReference.child("users").orderByChild("email").equalTo(firebaseAuth.getCurrentUser().getEmail());
       Log.v(TAG, "My Query is here" + q);
       q.addListenerForSingleValueEvent(new ValueEventListener() {
           @Override
           public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
               for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {
                   if (postSnapshot.getValue() != null) {
                       Log.v(TAG, "DataSnaptshoot is here" + postSnapshot);
                       String value = dataSnapshot.getValue(String.class);
                      username_profile.setText(value);
                      user_email.setText(value);

                       /*
                       User user= dataSnapshot.child(uId).getValue(User.class);
                       String name = user.getName();
                       String email = user.getEmail();
                       username_profile.setText("User name: "+name);
                       user_email.setText("Email:"+email);
                       */
                   }
              }
           }

           @Override
           public void onCancelled(@NonNull DatabaseError databaseError) {
               Toast.makeText(ProfileActivity.this,databaseError.getCode(),Toast.LENGTH_LONG).show();
           }
       });


       //displaying logged in user name
      // username_profile = findViewById(R.id.username_profile_student);
       //user_email = findViewById(R.id.email_profile_student);


       //username_profile.setText(user.getDisplayName());
       //user_email.setText("Email: "+user.getEmail());


       logout = findViewById(R.id.btnLogout);
       profilePic =findViewById(R.id.profile_pic);

       logout.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               //if logout is pressed
               if (v == logout) {
                   //logging out the user
                   firebaseAuth.signOut();
                   //closing activity
                   finish();
                   //starting login activity
                   startActivity(new Intent(ProfileActivity.this, StudentLogin.class));
               }
           }
       });

       profilePic.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View arg0) {
               OpenGallery();

           }
       });

   }
   //=============Gallery===Code=for=Image===========================================================
   private void  OpenGallery()
   {
       Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
       startActivityForResult(gallery,PICK_IMAGE);
   }

   @Override
   protected void onActivityResult(int requestCode, int resultCode, Intent data)
   { super.onActivityResult(requestCode,resultCode,data);

       if(resultCode == RESULT_OK && requestCode == PICK_IMAGE)
       {
           imagePath = data.getData();
           profilePic.setImageURI(imagePath);
       }
   }

   //================================================================================================
}
 
Saloon Keeper
Posts: 5344
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a lot of code, which is barely legible without CODE tags. What does it do, what should it be doing instead, and what problems do you have making the required changes? TellTheDetails
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!